After some divide & conquer debugging I found one thing that sounds like a bug.
If I cd into my buildSrc folder, and build, I get a different result based on whether an empty settings.gradle exists in the parent folder. I confirmed this with a minimal test case.
If …/settings.gradle exists, then the
Compiler arguments: … -classpath
is prepended by the gradle dependencies as above.
If there is no …/settings.gradle, then the same “gradle build” command does not add any gradle dependencies to the compiler classpath.
Here’s a shell session that illustrates the problem. “gradle clean” fails the first run, but after deleting the empty settings.gradle it succeeds:
~/src/test/gradle/commons-codec/buildSrc %> gradle clean :buildSrc:compileJava /Users/bedge/src/test/gradle/commons-codec/buildSrc/src/main/java/com/nim/Sha1.java:24: error: cannot find symbol
sha1 = DigestUtils.sha1Hex(new FileInputStream(sourceFile));
^
symbol:
method sha1Hex(FileInputStream)
location: class DigestUtils 1 error :buildSrc:compileJava FAILED
FAILURE: Build failed with an exception.
-
What went wrong: Execution failed for task ‘:compileJava’. > Compilation failed; see the compiler error output for details.
-
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.134 secs ~/src/test/gradle/commons-codec/buildSrc %> rm …/settings.gradle ~/src/test/gradle/commons-codec/buildSrc %> gradle clean :clean
BUILD SUCCESSFUL
Total time: 0.779 secs
This specific failure is because gradle’s prepended dependencies put commons-codec 1.6 on the classpath and the sha1Hex in the error above is only in 1.8.
Here is the buildSrc/build.gradle:
apply plugin: 'groovy'
apply plugin: 'eclipse'
tasks.withType(Compile) {
options.compilerArgs << "-Xlint:deprecation"
}
dependencies {
compile(group: 'com.google.code.gson', name: 'gson', version: '2.2.4')
compile(group: 'org.slf4j', name: 'slf4j-api', version: '1.7.5')
compile(group: 'commons-lang', name: 'commons-lang', version: '2.6')
compile(group: 'commons-io', name: 'commons-io', version: '2.4')
compile(group: 'commons-collections', name: 'commons-collections', version: '3.2.1')
compile(group: 'commons-codec', name: 'commons-codec', version: '1.8')
compile(group: 'org.apache.pdfbox', name: 'pdfbox', version: '1.8.2')
compile(group: 'com.nativelibs4java', name: 'bridj', version: '0.6.2')
compile(group: 'com.typesafe', name: 'config', version: '1.0.2')
compile group: 'org.slf4j', name:'slf4j-api', version: '1.6.4'
def logbackVersion = '1.0.13'
testRuntime group: 'ch.qos.logback', name:'logback-classic', version: logbackVersion
testRuntime group: 'ch.qos.logback', name:'logback-core', version: logbackVersion
testCompile 'junit:junit:4.8.1'
compile("org.codehaus.groovy:groovy-all:2.1.7")
testCompile "org.spockframework:spock-core:1.0-groovy-2.0-SNAPSHOT"
testCompile "org.hamcrest:hamcrest-core:1.3"
testRuntime "cglib:cglib-nodep:2.2.2"
testRuntime "org.objenesis:objenesis:1.2"
}
repositories {
mavenCentral()
/* No local maven repo, use content-parser-v4/lib instead, this works for both
installed /opt/nim/parserV4 as well as source tree invokation
mavenLocal() */
maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
}
This is only part of the problem as it still happens when I build from the parent folder. That is, I still get the prepended gradle deps when building in the parent folder.