[GRADLE-1575] compile dependencies mixed with groovy depencencies (commons cli) Created: 26/May/11  Updated: 23/Jan/13  Resolved: 23/Jan/13

Status: Resolved
Project: Gradle
Affects Version/s: 1.0-milestone-2
Fix Version/s: None

Type: Bug
Reporter: Daniel Gredler Assignee: Unassigned
Resolution: Not A Bug Votes: 0

Attachments: Zip Archive test.zip    

 Description   

Using the following example build script:

apply plugin: 'groovy'

repositories {
	mavenCentral()
}

dependencies {
	groovy 'org.codehaus.groovy:groovy:1.8.0'
	compile 'commons-cli:commons-cli:1.1'
}

Groovy 1.8.0 uses Commons CLI 1.2 [1], but if you specify that your project contains a user-defined compile dependency on Commons CLI 1.1 (as I do above), then version 1.1 gets used not only on the compile classpath, but also on the Groovy compilation classpath. So e.g. if you run "gradle compileGroovy --debug", here is an example of the log of the (erroneous) command line used:

12:44:06.130 [DEBUG] [org.gradle.api.internal.project.ant.AntLoggingAdapter] Execute:Java13CommandLauncher: Executing 'C:\Program Files\Java\jdk1.5.0_09\jre\bin\java' with arguments:
'-classpath'
'C:\Documents and Settings\dgredler\.gradle\cache\commons-cli\commons-cli\jars\commons-cli-1.1.jar;C:\Documents and Settings\dgredler\.gradle\cache\org.codehaus.groovy\groovy\jars\groovy-1.8.0.jar;C:\Documents and Settings\dgredler\.gradle\cache\antlr\antlr\jars\antlr-2.7.7.jar;C:\Documents and Settings\dgredler\.gradle\cache\asm\asm\jars\asm-3.2.jar;C:\Documents and Settings\dgredler\.gradle\cache\asm\asm-commons\jars\asm-commons-3.2.jar;C:\Documents and Settings\dgredler\.gradle\cache\asm\asm-tree\jars\asm-tree-3.2.jar;C:\Documents and Settings\dgredler\.gradle\cache\asm\asm-util\jars\asm-util-3.2.jar;C:\Documents and Settings\dgredler\.gradle\cache\asm\asm-analysis\jars\asm-analysis-3.2.jar;C:\java\gradle-1.0-milestone-2\lib\commons-cli-1.2.jar'
'-Dfile.encoding=Cp1252'
'org.codehaus.groovy.tools.FileSystemCompiler'
'--classpath'
'C:\Documents and Settings\dgredler\.gradle\cache\commons-cli\commons-cli\jars\commons-cli-1.1.jar;C:\Documents and Settings\dgredler\.gradle\cache\org.codehaus.groovy\groovy\jars\groovy-1.8.0.jar;C:\Documents and Settings\dgredler\.gradle\cache\antlr\antlr\jars\antlr-2.7.7.jar;C:\Documents and Settings\dgredler\.gradle\cache\asm\asm\jars\asm-3.2.jar;C:\Documents and Settings\dgredler\.gradle\cache\asm\asm-commons\jars\asm-commons-3.2.jar;C:\Documents and Settings\dgredler\.gradle\cache\asm\asm-tree\jars\asm-tree-3.2.jar;C:\Documents and Settings\dgredler\.gradle\cache\asm\asm-util\jars\asm-util-3.2.jar;C:\Documents and Settings\dgredler\.gradle\cache\asm\asm-analysis\jars\asm-analysis-3.2.jar;C:\java\gradle-1.0-milestone-2\lib\commons-cli-1.2.jar'
'-j'
'-Fg'
'-Jsource=1.5'
'-Jtarget=1.5'
'-d'
'C:\work\trunk\Core\r2\Development\Sources\xbo\test\build\classes\main'
'C:\work\trunk\Core\r2\Development\Sources\xbo\test\src\main\groovy\Test.java'

As you can see, there are two classpaths: the run classpath used to run the FileSystemCompiler class, and the compile classpath. Both of these classpaths contain two versions of Commons CLI: version 1.2 included with Gradle, and version 1.1 specified by the user as a compile dependency. In my opinion the run classpath above should contain only Gradle's version of CLI, whereas the compile classpath should contain only the user-specified version of CLI, not Gradle's version.

[1] https://svn.codehaus.org/groovy/tags/GROOVY_1_8_0/build.gradle



 Comments   
Comment by Daniel Gredler [ 26/May/11 ]

attaching test project

Comment by Daniel Gredler [ 26/May/11 ]

I should have mentioned that this mixing of two versions of CLI, specifically on the compilation run classpath, results in version 1.1 being used instead of version 1.2. Version 1.1 behaves differently from version 1.2, the result being that of the two "-Jsource=x -Jtarget=y" arguments, the second one gets interpreted as a file path, resulting in the following compilation failure:

C:\work\trunk\Core\r2\Development\Sources\xbo\test>gradle compileGroovy
:compileJava UP-TO-DATE
:compileGroovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
target=1.5: target=1.5 (The system cannot find the file specified)

1 error

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':compileGroovy'.
    Cause: Forked groovyc returned error code: 1
  • 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: 13.704 secs

Comment by Luke Daley [ 23/Jan/13 ]

This is standard dependency conflict management.

You should use the `groovy-all` jar which internalises its dependencies to avoid this problem.

Generated at Wed Jun 30 11:59:02 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.