Problem with gradle version

I’m having a strange issue with gradle. My build task is working with version 1.0-milestone-2, but is not working with version 1.1.

In my project I have the following build.gradle:

apply plugin: 'java'
apply plugin: 'eclipse'
    version = '1.8-SNAPSHOT'
manifest.mainAttributes("Main-Class": "br.com.caelum.tubaina.Tubaina",
            "Class-Path": "lib/commons-logging-1.1.1.jar lib/commons-codec-1.4.jar lib/commons-cli-1.1.jar lib/gson-2.1.jar lib/commons-io-1.3.1.jar lib/httpclient-4.1.3.jar lib/httpcore-4.1.4.jar lib/freemarker-2.3.10.jar lib/jai_codec.jar lib/jai_core.jar lib/jai_imageio.jar lib/java2html-5.0.jar lib/log4j-1.2.12.jar lib/Tidy.jar lib/jericho-html-3.1.jar lib/itext-2.1.7.jar lib/xstream-1.4.2.jar lib/xmlpull-1.1.3.1.jar lib/xpp3_min-1.1.4c.jar")
              [compileJava, compileTestJava]*.options*.encoding='UTF-8'
  task zip(type: Zip) {
    from "$buildDir/libs"
    into('lib') {
        from configurations.runtime
    }
    into('etc') {
        from "etc/"
    }
    into('templates') {
        from "templates/"
    }
}
  repositories {
    mavenCentral()
    mavenRepo urls: 'https://repository.jboss.org/nexus/content/groups/public/'
}
  dependencies {
    compile group: 'net.htmlparser.jericho', name: 'jericho-html', version: '3.1'
    compile group: 'de.java2html', name: 'java2html', version: '5.0'
    compile group: 'log4j', name: 'log4j', version: '1.2.12'
    compile group: 'commons-io', name: 'commons-io', version: '1.3.1'
    compile group: 'commons-cli', name: 'commons-cli', version: '1.1'
    compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.1.3'
    compile group: 'org.freemarker', name: 'freemarker', version: '2.3.10'
    compile group: 'com.sun.media', name: 'jai_codec', version: '1.1.2_01'
    compile group: 'javax.media', name: 'jai_core', version: '1.1.2_01'
    compile group: 'com.sun.media', name: 'jai_imageio', version: '1.0_01'
    compile group: 'com.google.code.gson', name: 'gson', version: '2.1'
    compile group: 'com.lowagie', name: 'itext', version: '2.1.7'
    compile group: 'com.thoughtworks.xstream', name: 'xstream', version: '1.4.2'
            testCompile group: 'junit', name: 'junit', version: '4.+'
    testCompile group: 'org.mockito', name: 'mockito-all', version: '1.9.0'
    compile files(fileTree(dir:"$projectDir/lib" as File, includes: ['*.jar']))
}

Using gradle-1.1, I get the following error:

csokol@clockwork:~/tmp/tubaina (master)$ ~/downloads/gradle-1.1/bin/gradle build
The 'urls' property of the RepositoryHandler.mavenRepo() method is deprecated and will be removed in a future version of Gradle. You should use the 'url' property to define the core maven repository & the 'artifactUrls' property to define any additional artifact locations.
:compileJava
Download http://repo1.maven.org/maven2/net/htmlparser/jericho/jericho-html/3.1/jericho-html-3.1.pom
Download http://repo1.maven.org/maven2/org/apache/httpcomponents/httpclient/4.1.3/httpclient-4.1.3.pom
Download http://repo1.maven.org/maven2/org/apache/httpcomponents/httpcomponents-client/4.1.3/httpcomponents-client-4.1.3.pom
Download http://repo1.maven.org/maven2/org/apache/httpcomponents/project/5/project-5.pom
Download http://repo1.maven.org/maven2/com/google/code/gson/gson/2.1/gson-2.1.pom
Checksum missing at https://repository.jboss.org/nexus/content/groups/public/com/google/code/gson/gson/2.1/gson-2.1.pom.sha1 due to: Could not GET 'https://repository.jboss.org/nexus/content/groups/public/com/google/code/gson/gson/2.1/gson-2.1.pom.sha1'.
                                                                                                                                  Download https://repository.jboss.org/nexus/content/groups/public/com/google/code/gson/gson/2.1/gson-2.1.pom
Download http://repo1.maven.org/maven2/org/sonatype/oss/oss-parent/5/oss-parent-5.pom
Download http://repo1.maven.org/maven2/com/lowagie/itext/2.1.7/itext-2.1.7.pom
Download http://repo1.maven.org/maven2/com/thoughtworks/xstream/xstream/1.4.2/xstream-1.4.2.pom
Download http://repo1.maven.org/maven2/com/thoughtworks/xstream/xstream-parent/1.4.2/xstream-parent-1.4.2.pom
Download http://repo1.maven.org/maven2/org/codehaus/codehaus-parent/3/codehaus-parent-3.pom
Download http://repo1.maven.org/maven2/org/apache/httpcomponents/httpcore/4.1.4/httpcore-4.1.4.pom
Download http://repo1.maven.org/maven2/org/apache/httpcomponents/httpcomponents-core/4.1.4/httpcomponents-core-4.1.4.pom
Download http://repo1.maven.org/maven2/bouncycastle/bcmail-jdk14/138/bcmail-jdk14-138.pom
Download http://repo1.maven.org/maven2/bouncycastle/bcprov-jdk14/138/bcprov-jdk14-138.pom
Download http://repo1.maven.org/maven2/bouncycastle/bctsp-jdk14/138/bctsp-jdk14-138.pom
Download http://repo1.maven.org/maven2/xmlpull/xmlpull/1.1.3.1/xmlpull-1.1.3.1.pom
Download http://repo1.maven.org/maven2/xpp3/xpp3_min/1.1.4c/xpp3_min-1.1.4c.pom
Download http://repo1.maven.org/maven2/org/bouncycastle/bctsp-jdk14/1.38/bctsp-jdk14-1.38.pom
Download http://repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk14/1.38/bcprov-jdk14-1.38.pom
Download http://repo1.maven.org/maven2/org/bouncycastle/bcmail-jdk14/1.38/bcmail-jdk14-1.38.pom
  FAILURE: Build failed with an exception.
  * What went wrong:
Could not resolve all dependencies for configuration ':compile'.
> Could not resolve group:commons-io, module:commons-io, version:1.3.1.
  Required by:
      :tubaina:1.8-SNAPSHOT
   > Could not HEAD 'http://repo1.maven.org/maven2/commons-io/commons-io/1.3.1/commons-io-1.3.1.pom'.
  * Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  BUILD FAILED
  Total time: 1 mins 29.234 secs

While using older versions such as gradle-1.0-milestone-2, it works fine:

:compileJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
:processResources
:classes
:jar
:zip
:assemble
:compileTestJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /home/csokol/tmp/tubaina/src/test/java/br/com/caelum/tubaina/builder/replacer/ListReplacerTest.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:processTestResources
:testClasses
:test
:check
:build
  BUILD SUCCESSFUL
  Total time: 41.89 secs

Any ideas of what’s going on?

Version 1.0-milestone 5 introduced a new dependency manager implementation. Therefore, you might see a different behavior. I’d recommend cleaning your local cache for the milestone 2 release (check ~/.gradle) and try again.

A little side-note: The property urls of the mavenRepo method got deprecated. You should use url instead to unsure compatibility with future Gradle versions.

repositories {
    mavenRepo url: 'https://repository.jboss.org/nexus/content/groups/public/'
}

This looks like it was an intermittent network problem.

Try running again with ‘–refresh-dependencies’.

Still not working… I think it’s something related to jai-codec.

This simple script, works with fine with 1.0-milestone-2, but not with 1.1:

apply plugin: 'java'
apply plugin: 'eclipse'
    version = '1.8-SNAPSHOT'
manifest.mainAttributes("Main-Class": "br.com.caelum.tubaina.Tubaina",
   "Class-Path": "lib/commons-logging-1.1.1.jar lib/commons-codec-1.4.jar lib/commons-cli-1.1.jar lib/gson-2.1.jar lib/commons-io-1.3.1.jar lib/httpclient-4.1.3.jar lib/httpcore-4.1.4.jar lib/freemarker-2.3.10.jar lib/jai_codec.jar lib/jai_core.jar lib/jai_imageio.jar lib/java2html-5.0.jar lib/log4j-1.2.12.jar lib/Tidy.jar lib/jericho-html-3.1.jar lib/itext-2.1.7.jar lib/xstream-1.4.2.jar lib/xmlpull-1.1.3.1.jar lib/xpp3_min-1.1.4c.jar")
     [compileJava, compileTestJava]*.options*.encoding='UTF-8'
  repositories {
    mavenCentral()
    mavenRepo urls: 'https://repository.jboss.org/nexus/content/groups/public/'
}
  dependencies {
    compile group: 'com.sun.media', name: 'jai_codec', version: '1.1.2_01'
    compile group: 'javax.media', name: 'jai_core', version: '1.1.2_01'
    compile group: 'com.sun.media', name: 'jai_imageio', version: '1.0_01'
 compile files(fileTree(dir:"$projectDir/lib" as File, includes: ['*.jar']))
}

If POM and Jar exist in different repositories, the following configuration needs to be used:

repositories {
    maven {
        url "http://repo1.maven.org/maven2"
        artifactUrls "https://repository.jboss.org/nexus/content/groups/public/"
    }
}

However, neither of the two repositories contains the jai_codec Jar, which explains why resolution fails. My best guess is that you already have the Jar in the Ivy cache used by the old Gradle version, brought in by some other build. Recent Gradle versions make sure that such reproducibility problems can’t occur.

Actually, I just realize that jai-codec jars are placed at lib/ subdir in my project. Maybe the older version automatically find those jars from that dir.

I think I’m having the same problems raised at this topic: http://forums.gradle.org/gradle/topics/jai_depedency_download and this open issue at gradle bug tracker: http://issues.gradle.org/browse/GRADLE-2395

I’ve tried the solutions proposed there but none of them solved my problem. For now, I just removed those dependencies (since I already have those jars), but it still would be nice to have those dependencies documented explicitly at build.gradle script.

When Gradle looks for the Jar corresponding to a POM, it only looks in Maven repositories. So either you have to to put the Jar into a Maven repository (could be local and committed to source control), or you remove the Maven dependency declaration and just use the file-based approach (see your last ‘compile’ dependency).