Gradle Groovy Library Scope - documentation/best practices (Grapes)

Dear Gradle Team and Community,

With reference to https://guides.gradle.org/building-groovy-libraries/

(Gradle 5.2.1)

I was building my Groovy library (this library is intended to be used as dependency for other projects) using build.gradle recommended in the above documentation web page:

...
dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.5.4' 
...
}
...

Here is the Build Scan: https://scans.gradle.com/s/mtq6qtse4jiv4

However when I try to load my library using Grapes in Groovy Console with different version (e.g. 2.5.6), I get error.

Problematic script:

@Grab('io.infinite:supplies:1.1.1')

def i

Error:

groovy.lang.GroovyRuntimeException: Conflicting module versions. Module [groovy-xml is loaded in version 2.5.6 and you are trying to load version 2.5.4

My project branch where issue is simulated:

The problem does not appear if I use the below build.gradle:

...
dependencies {
    compileOnly 'org.codehaus.groovy:groovy-all:2.5.4' 
    testCompile 'org.codehaus.groovy:groovy-all:2.5.4' 
...
}
...

Question: where is there problem? :slight_smile:
a) In Gradle documentation/best practice (groovy-all scope needs to be changed to compileOnly)?
b) In Groovy Console?
c) In Grapes?

PS: I tried using groovy module and certain specific modules explicitly (groovy-xml, groovy-swing, etc) - same issue persists.

PPS: No spock is used.

1 Like

After discussing with the Groovy Team, the tendency is to submit PR for https://guides.gradle.org/building-groovy-libraries/

As per Paul King’s kind suggestion:


Previous examples assumed that the consumer of the library will transitively want the Groovy jars on the classpath. For libraries that will be consumed in contexts where Groovy will already be on the classpath, you can consider altering your dependency scopes as follows:

dependencies {
    compileOnly 'org.codehaus.groovy:groovy-all:2.5.4'
    testCompile 'org.codehaus.groovy:groovy-all:2.5.4'
}

Alternatively, you may wish to document to your users that they may need to exclude transitive dependencies or specifically exclude the Groovy jar to avoid having two (potentially conflicting) versions of Groovy on the classpath.


PR is submitted: https://github.com/gradle-guides/building-groovy-libraries/pull/6

Just a kind reminder. Thank you.