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

63,276

Solution 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"
    }
    ....
}

Solution 2

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

Solution 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

Solution 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

Solution 5

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

Try:

./gradlew

instead of

gradle

Share:
63,276

Related videos on Youtube

Mike Slinn
Author by

Mike Slinn

I am the managing editor of ScalaCourses.com and a software expert witness in the USA and Europe. I published Stack Overflow Culture: Zero-Sum, Authoritarian and Hormonally Imbalanced on 2021-04-18.

Updated on July 09, 2022

Comments

  • Mike Slinn
    Mike Slinn almost 2 years

    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.

    • JB Nizet
      JB Nizet over 9 years
      You're probably using an old version of gradle that doesn't have this method yet. What does gradle -version say?
    • Mike Slinn
      Mike Slinn over 9 years
      Installed via apt-get today on XUbuntu. $ gradle -version ------------------------------------------------------------ Gradle 1.5 ------------------------------------------------------------ Gradle build time: Sunday, June 15, 2014 3:27:36 PM UTC Groovy: 1.8.6 Ant: Apache Ant(TM) version 1.9.4 compiled on May 9 2014 Ivy: non official version JVM: 1.8.0_25 (Oracle Corporation 25.25-b02) OS: Linux 3.16.0-28-generic amd64
    • Peter Niederwieser
      Peter Niederwieser over 9 years
      Thats quite an old Gradle version which indeed doesn't have jcenter(). Of course you can always configure JCenter as a regular Maven repository (maven { url "..." }), rather than using the shortcut.
    • JB Nizet
      JB Nizet over 9 years
      gradle 1.5 is very very old. The current version is 2.2.1. The last 1.x version was 1.12. You should upgrade, and also consider using the gradle wrapper: gradle.org/docs/current/userguide/gradle_wrapper.html.
    • Mike Slinn
      Mike Slinn over 9 years
      So the Gradle provided by apt-get is out of date. I wonder how to notify the appropriate people so they can update the .deb? I'll add this ppa, seems like it should give me the current version: launchpad.net/~cwchien/+archive/ubuntu/gradle
    • Mike Slinn
      Mike Slinn over 9 years
      Hmm, seems like my build.gradle is inadequate, and/or my ~/.gradle contents need more definiions FAILURE: Build failed with an exception. * What went wrong: Some problems were found with the configuration of task ':bintrayUpload'. > No value has been specified for property 'packageName'. > No value has been specified for property 'user'. > No value has been specified for property 'apiKey'. > No value has been specified for property 'repoName'.
  • Mike Slinn
    Mike Slinn over 9 years
    I updated Grade by using cwchein's PPA. Seems no-one maintains the .deb in the default Debian repo. However, I am stuck on the current errors: > No value has been specified for property 'packageName'. > No value has been specified for property 'user'. > No value has been specified for property 'apiKey'. > No value has been specified for property 'repoName'. Some of those values are in build.gradle, what's wrong?
  • JBaruch
    JBaruch over 9 years
    I'd say those are separate problems that deserve a separate question. If jcenter() works, I'd accept the answer and move on. I'll be glad to help on the other issue in a question dedicated to it.
  • Mike Slinn
    Mike Slinn over 9 years
    From Twitter: baruch mslinn because DSL has changed. You are using 1.0 with DSL for 0.6. We’ll update.
  • JBaruch
    JBaruch over 9 years
    Our twitter discussion has nothing to do with this question (and the correct answer). jcenter was added in 1.7, that's why it fails in older version. Why did you remove the accept and the vote?
  • Mike Slinn
    Mike Slinn over 9 years
    The final sentence in the posting is: "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."
  • JBaruch
    JBaruch over 9 years
    So I perfectly answered the first question and would close the second for being too broad.
  • matbrgz
    matbrgz over 8 years
    I had to download a suitable new gradle to be able to run "gradle wrapper".
  • Barry Staes
    Barry Staes about 6 years
    This worked for me. I used latest distributionUrl value according to developer.android.com/studio/releases/gradle-plugin.html
  • Mike Slinn
    Mike Slinn almost 6 years
    This answer pertains to Android, instead of Scala / SBT
  • Eshan Chattaraj
    Eshan Chattaraj almost 6 years
    @MikeSlinn This is Android Gradle file only..This is not Scala..Please Check 1st and then Comment
  • Mike Slinn
    Mike Slinn almost 6 years
    I am the original poster. I wanted to use Gradle instead of SBT, which is used in Scala projects. You are talking about something else.
  • Sagar Patel
    Sagar Patel about 5 years
    I get issue while publishing jFrog Artifactory. it will show me "cannot find symbol return data().preference().getDeviceId();" Here deviceId is not there in generated Prefrence Interface. But its actually there in my code. it is like Transitive dependency. deviceId is a part of my coreData Module and coreData is imported in my coreSDK module. Please help @JBaruch