[ 
https://issues.apache.org/jira/browse/GROOVY-9165?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16859592#comment-16859592
 ] 

Remko Popma commented on GROOVY-9165:
-------------------------------------

After renaming the picocli jar in my groovy distribution to .jar.bak,  the 
correct picocli jar specified in the {{@Grab}} is loaded:
{code}
Groovy version 2.5.7
Picocli version 4.0.0-beta-1b
picocli location: 
jar:file:/C:/Users/remko/.groovy/grapes/info.picocli/picocli/jars/picocli-4.0.0-beta-1b.jar!/picocli/CommandLine.class
{code}

After checking the startup script more closely, I found that the class that 
bootstraps the program is {{org.codehaus.groovy.tools.GroovyStarter}} (not 
{{groovy.ui.GroovyMain}}).
This uses a 
[LoaderConfiguration|http://docs.groovy-lang.org/docs/latest/html/api/org/codehaus/groovy/tools/LoaderConfiguration.html]
 read from {{C:\apps\groovy-2.5.7\bin\..\conf\groovy-starter.conf}}, which 
contains the line 

{code}
    # load required libraries
    load !{groovy.home}/lib/*.jar
{code}

So all jars in lib (including picocli-3.9.5.jar) are loaded in the classpath of 
the script.

That configuration line above is not easy to change. The 
{{LoaderConfiguration}} class calls 
[Pattern.quote|https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#quote(java.lang.String)]
 on the {{/lib/*.jar}} string, and I think that means that it is not possible 
to add a regex that excludes for example any jar whose name starts with 
"picocli" (happy to be proven wrong though :-)).

At the moment, the LoaderConfiguration class has no facilities for excluding 
jars.
Would it be an idea to add such a facility?

{code}
#conf/groovy-starter.conf

    # load required libraries
    load !{groovy.home}/lib/*.jar
    # regex of libraries not to load
    load-exclude .*picocli.*.jar
{code}


> Grape cannot pull in picocli
> ----------------------------
>
>                 Key: GROOVY-9165
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9165
>             Project: Groovy
>          Issue Type: Improvement
>          Components: Grape, groovy-runtime
>    Affects Versions: 2.5.0, 2.5.1, 2.5.2, 2.5.3, 2.5.4, 2.5.5, 2.5.6, 2.5.7
>            Reporter: Remko Popma
>            Priority: Major
>
> If I try to run a Groovy script I am unable to pull in a newer version of 
> picocli via {{@Grab}}:
> {code:groovy}
> @Grab('info.picocli:picocli-groovy:4.0.0-beta-1b')
> @GrabExclude('org.codehaus.groovy:groovy-all')
> @picocli.groovy.PicocliScript
> @picocli.CommandLine.Command
> import picocli.CommandLine
> println "Groovy version ${GroovySystem.version}"
> println "Picocli version $CommandLine.VERSION"
>  {code}
> Depending on the Groovy version, this prints 
> {code}
> Groovy version 2.5.0
> Picocli version 3.0.2
> {code}
> or 
> {code}
> Groovy version 2.5.7
> Picocli version 3.9.5
> {code}
> So the {{@Grab('info.picocli:picocli-groovy:4.0.0-beta-1b')}} is not honoured.
> This is because the {{groovy.ui.GroovyMain}} class, which executes Groovy 
> scripts, itself uses picocli to parse the command line parameters. 
> Unfortunately, this means that Groovy script authors cannot control the 
> picocli version used by their scripts.
> Is there anything we can do to improve this?



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to