Could not find method jcenter() for arguments [] on repository container

元气小坏坏 提交于 2019-11-30 07:44:55

问题


I'm new to Gradle and bintray. I want to publish this project so it is readily available to Maven and SBT users. I am not the original author of this package; it appears to have been abandoned; I just want to publish the current HEAD.

~/.gradle/gradle.properties is something like:

bintrayUser=mslinn
bintrayKey=blahblah

build.gradle looks like this.:

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'
}

Here is the problem:

$ 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

I'm looking for advice on how to solve the error message, and advice on any setup issues I am likely to encounter including this project into JCenter so the published bintray project is available to all.


回答1:


Just to summarize the discussion in comments:

Gradle added jcenter() shortcut in version 1.7. Any version prior to it will fail with this exception. You can still work with jcenter by adding it as a normal maven repo:

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



回答2:


I got this in an Android project, needed to upgrade Gradle to 4.1 in gradle-wrapper.properties.




回答3:


Goto the Android project Tab, in explorer collapse Gradle Scripts.You will find a file called gradle-wrapper.properties .

Open the file and select all and paste the following code below:

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

Sync now

But before that You have to make changes in build.gradle (Project) file

Open the file select All and Copy into entire sheet the below code:

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
}

Sync Now




回答4:


I ran into the same error. The following method (as described here) worked for me.

Add a task

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

and run it once. Afterwards, start using gradlew instead of gradle




回答5:


got this error when building an android app on command-line with the gradle command

Try:

./gradlew

instead of

gradle




回答6:


I had the same trouble. In my case, it was a newie mistake. Maybe it could be helpful for anyone. I reverted the code from the one I changed to the original one.

The code as I changed it:

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

The original code:

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



回答7:


It happened with me when I stopped the gradle downloading in between, to resolve this we have to delete the older gradle and update and sync

to delete use

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

to udpate, add this to your graddle-properties : distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

And then sync



来源:https://stackoverflow.com/questions/27470443/could-not-find-method-jcenter-for-arguments-on-repository-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!