how to run *.groovy scripts in a jar with gmavenplus:execute

348 views
Skip to first unread message

Torsten Reinhard

unread,
Sep 28, 2016, 6:21:13 AM9/28/16
to GMavenPlus
Hi,

I want to run my own script "whatever.groovy" - packaged in a jar file:

myJar:
 
- com/package
       
-- MyClass.class
 
- whatever.groovy


How do I need to setup this ?

<plugin>
   
<groupId>org.codehaus.gmavenplus</groupId>
   
<artifactId>gmavenplus-plugin</artifactId>
   
<version>1.5</version>

   
<configuration>
<!-- how to reference the script here? -->
<!-- file:///path/to/file was working, but now it´s available in a jar file -->
       
<scripts>
           
<script>classpath:whatever.groovy</script>
       
</scripts>
   
</configuration>

   
<dependencies>
     
<dependency>
       
<groupId>com.package</groupId>
       
<artifactId>myjar</artifactId>
        ...
     
</dependency>
   
</dependencies>


Thanx for any advice,

Torsten

Torsten Reinhard

unread,
Sep 28, 2016, 8:49:51 AM9/28/16
to GMavenPlus
After some tries this worked finally - but isn´t there a better way ?

<configuration>
<!-- how to reference the script here? -->
<!-- file:///path/to/file was working, but now it´s available in a jar file -->
 
<scripts>
    <script>jar:file:/${settings.localRepository}/com/package/0.1-SNAPSHOT/myjar-0.1-SNAPSHOT.jar!/whatever.groovy</script>
  </scripts>
</configuration>

Keegan Witt

unread,
Oct 11, 2016, 1:05:16 PM10/11/16
to Torsten Reinhard, GMavenPlus

Hi Torsten,
First of all, I'm very sorry for the late reply.  This got buried in my inbox and I'm just noticing it now.

One thing you could do, since all dependencies are available on the script's classpath would be to invoke the class that is automatically assigned by Groovy if you haven't explicitly added a main class in your script (with the same name as the script).  So if you have a script called foo.groovy in a jar that's brought in as a dependency, it could be invoked like

<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>

<configuration>
    <scripts>
<script>whatever.main()</script>
    </scripts>
</configuration>

<dependencies>
<dependency>
<groupId>com.package</groupId>
<artifactId>myjar</artifactId>
    </dependency>
</dependencies>
</plugin>

I haven't had a chance to test it out, but it should work.

-Keegan


--
You received this message because you are subscribed to the Google Groups "GMavenPlus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gmavenplus+unsubscribe@googlegroups.com.
To post to this group, send email to gmave...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gmavenplus/95b8366e-af5a-4c09-8d0d-2008021b0ed9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Torsten Reinhard

unread,
Oct 21, 2016, 2:18:53 AM10/21/16
to Keegan Witt, GMavenPlus
Hi thanx,

I got it now,using the Scripts run() method:
...
<scripts>
<script>new configure( new Binding(args.split(',') as String[])).run()</script>
</scripts>
<properties>
<args>--verbose,--out,.........</<args>
</properties>
...

Best regards,
-Torsten

Von: Keegan Witt
Gesendet: ‎11.‎10.‎2016 19:05
An: Torsten Reinhard
Cc: GMavenPlus
Betreff: Re: how to run *.groovy scripts in a jar with gmavenplus:execute

Reply all
Reply to author
Forward
0 new messages