You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by on 2019/03/24 14:32:36 UTC

Potential questionable situation in Grapes Module Loading

Dear Groovy Dev Mailing List,

When I follow Gradle recommendations in terms of dependency scopes of my Groovy Library, in the end it produces errors when loaded via Grapes from Groovy Console/Groovy Shell:

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

The build.gradle contains nothing more than the below in terms of dependencies:

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

Question: the Gradle documentation has to be fixed, or there is bug in Grapes?

Gradle documentation in question: https://guides.gradle.org/building-groovy-libraries/?_ga=2.99509400.76686785.1553433006-920887584.1535023978

Re: Potential questionable situation in Grapes Module Loading

Posted by .

On 2019/03/25 11:25:59, Paul King <pa...@asert.com.au> wrote: 
> I wouldn't use those exact words. I would say something like:
> "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:"
> 
> [build script sample as you have]
> 
> "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."
> 
> Cheers, Paul.
> 
> On Mon, Mar 25, 2019 at 6:07 PM anton.pryamostanov@gmail.com <
> anton.pryamostanov@gmail.com> wrote:
> 
> >
> >
> > On 2019/03/24 22:52:55, Paul King <pa...@asert.com.au> wrote:
> > > If your pom for this dependency 'io.infinite:supplies:1.1.1' mentions a
> > > specific version of groovy, then
> > > I would expect the kinds of errors you are seeing if you are loading
> > from a
> > > different version of Groovy.
> > > Either use the workarounds you mentioned on the gradle side - then you
> > have
> > > an implicit assumption
> > > that the library will always be used from a groovy environment with the
> > > needed dependencies, or add
> > > a @GrabExclude of Groovy on the Groovy side alongside your '@Grab(
> > > 'io.infinite:supplies:1.1.1')'.
> > >
> > > Cheers, Paul.
> > >
> > >
> > > On Mon, Mar 25, 2019 at 8:10 AM anton.pryamostanov@gmail.com <
> > > anton.pryamostanov@gmail.com> wrote:
> > >
> > > > Oh, I forgot to say: relevant thread on Gradle forum:
> > > >
> > https://discuss.gradle.org/t/gradle-groovy-library-scope-documentation-best-practices-grapes/31054
> > > >
> > > > It has some additional details (like workaround). Please kindly take a
> > > > look at that.
> > > >
> > > > Thank you.
> > > >
> > > > Bye (Anton)
> > > >
> > >
> >
> > Many thanks, Paul!
> >
> > Shall I initiate to change the Gradle documentation? Since it's a common
> > entry point for anyone writing Groovy library using Gradle build.
> >
> > My suggestion is to add there a block, saying - "For better compatibility
> > with other build tools, the recommended dependency scopes should be:"
> > ..
> > dependencies {
> >     compileOnly 'org.codehaus.groovy:groovy-all:2.5.4'
> >     testCompile 'org.codehaus.groovy:groovy-all:2.5.4'
> > ..
> > }
> > ..
> >

Brilliant, thanks Paul!
That will further address the risks of some degree of unasureness in relation to ivy/Maven/other build tools except Gradle and Grapes.
I will go ahead and submit PR to Grails documentation shortly.

Kind Regards,
Anton

Re: Potential questionable situation in Grapes Module Loading

Posted by Paul King <pa...@asert.com.au>.
I wouldn't use those exact words. I would say something like:
"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:"

[build script sample as you have]

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

Cheers, Paul.

On Mon, Mar 25, 2019 at 6:07 PM anton.pryamostanov@gmail.com <
anton.pryamostanov@gmail.com> wrote:

>
>
> On 2019/03/24 22:52:55, Paul King <pa...@asert.com.au> wrote:
> > If your pom for this dependency 'io.infinite:supplies:1.1.1' mentions a
> > specific version of groovy, then
> > I would expect the kinds of errors you are seeing if you are loading
> from a
> > different version of Groovy.
> > Either use the workarounds you mentioned on the gradle side - then you
> have
> > an implicit assumption
> > that the library will always be used from a groovy environment with the
> > needed dependencies, or add
> > a @GrabExclude of Groovy on the Groovy side alongside your '@Grab(
> > 'io.infinite:supplies:1.1.1')'.
> >
> > Cheers, Paul.
> >
> >
> > On Mon, Mar 25, 2019 at 8:10 AM anton.pryamostanov@gmail.com <
> > anton.pryamostanov@gmail.com> wrote:
> >
> > > Oh, I forgot to say: relevant thread on Gradle forum:
> > >
> https://discuss.gradle.org/t/gradle-groovy-library-scope-documentation-best-practices-grapes/31054
> > >
> > > It has some additional details (like workaround). Please kindly take a
> > > look at that.
> > >
> > > Thank you.
> > >
> > > Bye (Anton)
> > >
> >
>
> Many thanks, Paul!
>
> Shall I initiate to change the Gradle documentation? Since it's a common
> entry point for anyone writing Groovy library using Gradle build.
>
> My suggestion is to add there a block, saying - "For better compatibility
> with other build tools, the recommended dependency scopes should be:"
> ..
> dependencies {
>     compileOnly 'org.codehaus.groovy:groovy-all:2.5.4'
>     testCompile 'org.codehaus.groovy:groovy-all:2.5.4'
> ..
> }
> ..
>

Re: Potential questionable situation in Grapes Module Loading

Posted by .

On 2019/03/24 22:52:55, Paul King <pa...@asert.com.au> wrote: 
> If your pom for this dependency 'io.infinite:supplies:1.1.1' mentions a
> specific version of groovy, then
> I would expect the kinds of errors you are seeing if you are loading from a
> different version of Groovy.
> Either use the workarounds you mentioned on the gradle side - then you have
> an implicit assumption
> that the library will always be used from a groovy environment with the
> needed dependencies, or add
> a @GrabExclude of Groovy on the Groovy side alongside your '@Grab(
> 'io.infinite:supplies:1.1.1')'.
> 
> Cheers, Paul.
> 
> 
> On Mon, Mar 25, 2019 at 8:10 AM anton.pryamostanov@gmail.com <
> anton.pryamostanov@gmail.com> wrote:
> 
> > Oh, I forgot to say: relevant thread on Gradle forum:
> > https://discuss.gradle.org/t/gradle-groovy-library-scope-documentation-best-practices-grapes/31054
> >
> > It has some additional details (like workaround). Please kindly take a
> > look at that.
> >
> > Thank you.
> >
> > Bye (Anton)
> >
> 

Many thanks, Paul!

Shall I initiate to change the Gradle documentation? Since it's a common entry point for anyone writing Groovy library using Gradle build.

My suggestion is to add there a block, saying - "For better compatibility with other build tools, the recommended dependency scopes should be:"
..
dependencies {
    compileOnly 'org.codehaus.groovy:groovy-all:2.5.4' 
    testCompile 'org.codehaus.groovy:groovy-all:2.5.4' 
..
}
..

Re: Potential questionable situation in Grapes Module Loading

Posted by Paul King <pa...@asert.com.au>.
If your pom for this dependency 'io.infinite:supplies:1.1.1' mentions a
specific version of groovy, then
I would expect the kinds of errors you are seeing if you are loading from a
different version of Groovy.
Either use the workarounds you mentioned on the gradle side - then you have
an implicit assumption
that the library will always be used from a groovy environment with the
needed dependencies, or add
a @GrabExclude of Groovy on the Groovy side alongside your '@Grab(
'io.infinite:supplies:1.1.1')'.

Cheers, Paul.


On Mon, Mar 25, 2019 at 8:10 AM anton.pryamostanov@gmail.com <
anton.pryamostanov@gmail.com> wrote:

> Oh, I forgot to say: relevant thread on Gradle forum:
> https://discuss.gradle.org/t/gradle-groovy-library-scope-documentation-best-practices-grapes/31054
>
> It has some additional details (like workaround). Please kindly take a
> look at that.
>
> Thank you.
>
> Bye (Anton)
>

Re: Potential questionable situation in Grapes Module Loading

Posted by .
Oh, I forgot to say: relevant thread on Gradle forum: https://discuss.gradle.org/t/gradle-groovy-library-scope-documentation-best-practices-grapes/31054

It has some additional details (like workaround). Please kindly take a look at that.

Thank you.

Bye (Anton)

Re: Potential questionable situation in Grapes Module Loading

Posted by .

On 2019/03/24 21:01:43, Jochen Theodorou <bl...@gmx.org> wrote: 
> On 24.03.19 15:32, anton.pryamostanov@gmail.com wrote:
> > Dear Groovy Dev Mailing List,
> >
> > When I follow Gradle recommendations in terms of dependency scopes of my Groovy Library, in the end it produces errors when loaded via Grapes from Groovy Console/Groovy Shell:
> >
> > 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
> >
> > The build.gradle contains nothing more than the below in terms of dependencies:
> >
> > ..
> > dependencies {
> >      compile 'org.codehaus.groovy:groovy-all:2.5.4'
> > ..
> > }
> > ..
> >
> > Question: the Gradle documentation has to be fixed, or there is bug in Grapes?
> >
> > Gradle documentation in question: https://guides.gradle.org/building-groovy-libraries/?_ga=2.99509400.76686785.1553433006-920887584.1535023978
> 
> setting a compile dependency should not be done with Grapes. And afaik
> it is not done like that in Gradle. You have a class loader that tries
> to init the Groovy system for 2.5.4, while version 2.5.6 modules are
> visible and chosen by the class loading. In a "normal" Gradle setup this
> is not the case. I have used this in dozens of projects and it was never
> a problem because Gradle internally prevents this from happening.
> 
> So first of all... What gradle version and is 2.5.6 the groovy version
> in that gradle? If not where does it come from? If you do not even have
> a Groovy on your classpath and your build file contains only that
> dependencies declaration (plus a bit), then this sounds like a bug in
> gradle. But maybe, if you explain a bit more, we can find out if that is
> really the case or not
> 
> bye Jochen
> 
> bye Jochen
> 
>

Hi Jochen!

First of all it is a pleasure to talk with Groovy Core Team, and thanks for this opportunity to directly interact with you.

Coming to the questions: the Gradle build passes OK.
Gradle version is 5.2.1 and it only has "groovy-all" module with scope "compile" and version "2.5.4".
It produces JAR which is usable in other Gradle builds as Compile dependency with no issues - you are right.

However - when I try to load this module in Grapes via Groovy Console or Groovy shell (with different Groovy version e.g. 2.5.6 - I get the above error.

Here is the sample problematic script:
--
@Grab('io.infinite:supplies:1.1.1')

def i
--

- just try to run it in your Groovy console - you will see the 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

Since you mentioned that Gradle resolves this situation automatically - how difficult is to implement such mechanism in Grapes?

PS: I am not even sure if this mechanism is good or not. As said by Daniel Sun in Groovy Slack - it is not recommended combination of modules used for compilation and runtime, which can cause instability. And I agree with him. However compatibility-wise - it is very important feature in Gradle for Groovy.

Bye (Anton)

Re: Potential questionable situation in Grapes Module Loading

Posted by Jochen Theodorou <bl...@gmx.org>.
On 24.03.19 15:32, anton.pryamostanov@gmail.com wrote:
> Dear Groovy Dev Mailing List,
>
> When I follow Gradle recommendations in terms of dependency scopes of my Groovy Library, in the end it produces errors when loaded via Grapes from Groovy Console/Groovy Shell:
>
> 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
>
> The build.gradle contains nothing more than the below in terms of dependencies:
>
> ..
> dependencies {
>      compile 'org.codehaus.groovy:groovy-all:2.5.4'
> ..
> }
> ..
>
> Question: the Gradle documentation has to be fixed, or there is bug in Grapes?
>
> Gradle documentation in question: https://guides.gradle.org/building-groovy-libraries/?_ga=2.99509400.76686785.1553433006-920887584.1535023978

setting a compile dependency should not be done with Grapes. And afaik
it is not done like that in Gradle. You have a class loader that tries
to init the Groovy system for 2.5.4, while version 2.5.6 modules are
visible and chosen by the class loading. In a "normal" Gradle setup this
is not the case. I have used this in dozens of projects and it was never
a problem because Gradle internally prevents this from happening.

So first of all... What gradle version and is 2.5.6 the groovy version
in that gradle? If not where does it come from? If you do not even have
a Groovy on your classpath and your build file contains only that
dependencies declaration (plus a bit), then this sounds like a bug in
gradle. But maybe, if you explain a bit more, we can find out if that is
really the case or not

bye Jochen

bye Jochen