无法在存储库容器上找到参数[]的方法jcenter()

时间:2014-12-14 14:46:32

标签: gradle bintray jcenter

我是Gradle和bintray的新手。我想发布this project,以便Maven和SBT用户可以随时使用它。我不是这个包的原作者;它appears to have been abandoned;我只想发布当前的HEAD。

~/.gradle/gradle.properties类似于:

bintrayUser=mslinn
bintrayKey=blahblah

build.gradle看起来像这样。:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
    }
}
apply plugin: 'com.jfrog.bintray'

allprojects {
    apply plugin: 'idea'

    group = 'org.jfrog.example.bintray.gradle'
    version = '1.0'
}

subprojects {
    apply plugin: 'java'
    apply plugin: 'maven-publish'
    apply plugin: 'com.jfrog.bintray'

    sourceCompatibility = 1.6
    targetCompatibility = 1.6

    dependencies {
        testCompile 'junit:junit:4.7'
    }

    // custom tasks for creating source/javadoc jars
    task sourcesJar(type: Jar, dependsOn: classes) {
        classifier = 'sources'
        from sourceSets.main.allSource
    }

    task javadocJar(type: Jar, dependsOn: javadoc) {
        classifier = 'javadoc'
        from javadoc.destinationDir
    }

    // add javadoc/source jar tasks as artifacts
    artifacts {
        archives sourcesJar //, javadocJar
    }

    repositories {
        jcenter()
    }

    publishing {
        publications {
            mavenJava(MavenPublication) {
                if (plugins.hasPlugin('war')) {
                    from components.web
                } else {
                    from components.java
                }

                artifact sourcesJar {
                    classifier "sources"
                }

                artifact javadocJar {
                    classifier "javadoc"
                }
            }
        }
    }

    bintray {
        user = bintrayUser //this usually comes form gradle.properties file in ~/.gradle
        key = bintrayKey //this usually comes form gradle.properties file in ~/.gradle
        publications = ['mavenJava'] // see publications closure
        pkg { //package will be created if does not exist
            repo = 'Java-WebSocket'
//            userOrg = 'myorg' // an optional organization name when the repo belongs to one of the user's orgs
            name = 'Java-WebSocket'
            desc = 'Current HEAD of abandoned project'
            licenses = ['MIT']
            labels = ['websocket', 'java']
        }
    }
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.10'
}

问题在于:

$ gradle bintrayUpload

FAILURE: Build failed with an exception.

* Where:
Build file '/var/work/experiments/websockets/Java-WebSocket/build.gradle' line: 3

* What went wrong:
A problem occurred evaluating root project 'Java-WebSocket'.
> Could not find method jcenter() for arguments [] on repository container.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

我正在寻找有关如何解决错误消息的建议,以及我可能遇到的任何设置问题的建议,包括将此项目导入JCenter,以便所有人都可以使用已发布的bintray项目。

8 个答案:

答案 0 :(得分:48)

总结一下评论中的讨论:

Gradle在1.7版中添加了jcenter()快捷方式。之前的任何版本都将因此异常而失败。 您仍然可以使用jcenter将其添加为普通的maven repo:

repositories {
    maven {
        url "https://jcenter.bintray.com"
    }
    ....
}

答案 1 :(得分:5)

我在Android项目中得到了这个,需要在gradle-wrapper.properties中将Gradle升级到4.1。

答案 2 :(得分:4)

我遇到了同样的错误。以下方法(如here所述)为我工作。

添加任务

task wrapper(type: Wrapper) {
    gradleVersion = '2.0'
}

并运行一次。 然后,开始使用gradlew代替gradle

答案 3 :(得分:2)

  

在资源管理器折叠Gradle脚本中转到Android 项目标签。您将   找到一个名为 gradle-wrapper.properties 的文件。

打开文件并全选,然后在下面粘贴以下代码:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

立即同步

  

但是在此之前,您必须在 build.gradle(项目)文件中进行更改

打开文件,选择“全部”,然后将以下代码复制到整个工作表中:

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'
        classpath 'com.google.gms:google-services:4.0.0'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {url 'https://jitpack.io'}
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

立即同步

答案 4 :(得分:0)

我也遇到了同样的麻烦。就我而言,这是一个新手错误。也许对任何人都有帮助。 我将代码从更改的代码恢复为原始的代码。

我更改的代码:

buildscript {
    ext.kotlin_version = '1.2.71'
    repositories { google()  jcenter()
    }

原始代码:

buildscript {
    ext.kotlin_version = '1.2.71'
    repositories {
        google()
        jcenter()
    }

答案 5 :(得分:0)

使用gradle命令在命令行上构建android应用时,出现此错误

尝试:

  

./ gradlew

代替

  

渐变

答案 6 :(得分:0)

当我停止两者之间的gradle下载时,发生了我的事情,要解决此问题,我们必须删除较旧的gradle并进行更新和同步

删除使用

task clean(type: Delete) {
delete rootProject.buildDir
}

要添加,请将其添加到您的graddle-properties中:    distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

然后同步

答案 7 :(得分:0)

听起来很愚蠢,请确保您在自己的行上有jcenter。我复制粘贴了一些代码,最后以jcenter结束了一行。

allprojects {
    repositories {
        google {
            content {
                ...
            }
        }                  jcenter() // DERP
        maven { url "https://jitpack.io" }
        maven { url 'https://maven.google.com/' } 
    }
}