maven


Exception in using maven-antrun-plugin for Groovy compilation


I have a bunch of Groovy files that I need to include into a jar file along with Java classes. For the beginning I created the separate Maven xml file just for Groovy compiling. The result is the Zip Exception.
The Maven XML script is as follows:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycomp.MyGroovy</groupId>
<artifactId>MyGroovy</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>GroovyBuild</name>
<dependencies>
<dependency>
<groupId>groovy</groupId>
<artifactId>groovy-all-1.0-jsr</artifactId>
<version>05</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>WEB-INF/src/main/groovy</sourceDirectory>
<outputDirectory>WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<configuration>
<tasks>
<taskdef name="groovyc"
classname="org.codehaus.groovy.ant.Groovyc">
<classpath refid="maven.compile.classpath"/>
</taskdef>
<mkdir dir="${basedir}/target/WEB-INF/classes"/>
<groovyc destdir="${basedir}/target/WEB-INF/classes"
srcdir="${basedir}/WEB-INF/src/main/groovy" listfiles="true">
<classpath refid="maven.compile.classpath"/>
</groovyc>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Some extractions from the Maven debugging log:
[groovyc] Compiling 5 source files to /usr/java/ep622/com.elasticpath.core/target/WEB-INF/classes
[groovyc] /usr/java/ep622/com.elasticpath.core/WEB-INF/src/main/groovy/com/elasticpath/tags/builder/BuilderString.groovy
[groovyc] /usr/java/ep622/com.elasticpath.core/WEB-INF/src/main/groovy/com/elasticpath/tags/builder/LogicalTreeBuilder.groovy
[groovyc] /usr/java/ep622/com.elasticpath.core/WEB-INF/src/main/groovy/com/elasticpath/tags/engine/LogicalOperator.groovy
[groovyc] /usr/java/ep622/com.elasticpath.core/WEB-INF/src/main/groovy/com/elasticpath/tags/engine/MapRunner.groovy
[groovyc] /usr/java/ep622/com.elasticpath.core/WEB-INF/src/main/groovy/com/elasticpath/tags/engine/OperatorDelegate.groovy
Finding class org.codehaus.groovy.control.CompilationUnit
Loaded from /Users/anarinsky/.m2/repository/groovy/groovy-all-1.0-jsr/05/groovy-all-1.0-jsr-05.jar org/codehaus/groovy/control/CompilationUnit.class
--------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.3:run (compile) on project MyGroovy: An Ant BuildException has occured: java.util.zip.ZipException: error in opening zip file -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.3:run (compile) on project MyGroovy: An Ant BuildException has occured: java.util.zip.ZipException: error in opening zip file
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
Caused by: org.apache.maven.plugin.MojoExecutionException: An Ant BuildException has occured: java.util.zip.ZipException: error in opening zip file
at org.apache.maven.plugin.antrun.AbstractAntMojo.executeTasks(AbstractAntMojo.java:131)
at org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:98)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 19 more
Caused by: java.util.zip.ZipException: error in opening zip file
at org.codehaus.groovy.ant.Groovyc.compile(Groovyc.java:480)
at org.codehaus.groovy.ant.Groovyc.execute(Groovyc.java:376)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:357)
at org.apache.maven.plugin.antrun.AbstractAntMojo.executeTasks(AbstractAntMojo.java:118)
... 22 more
Caused by: java.util.zip.ZipException: error in opening zip file
at org.apache.tools.ant.AntClassLoader.addPathElement(AntClassLoader.java:460)
at org.codehaus.groovy.ant.Groovyc.buildClassLoaderFor(Groovyc.java:511)
at org.codehaus.groovy.ant.Groovyc.compile(Groovyc.java:469)
... 32 more
First, the compilation classes in your Groovy JSR jar are really ancient. I wouldn't advise using that as your dependency from which you define the Groovyc class. This is quite probably the cause of your issue. I'm not sure which you were trying to do. If you wanted to invoke via JSR223, no sense in compiling. If you're compiling, no sense in using the JSR dependency.
Moving on. Here's a full example including test classpaths that uses the latest Groovy versions: https://gist.github.com/keeganwitt/d56b4b81165a264061d5. If you're using Maven, I'd strongly advise you consider GMavenPlus (or Groovy-Eclipse Compiler Plugin for Maven if you prefer). I've done a comparison to try to help people choose here: http://docs.codehaus.org/display/GMAVENPLUS/Choosing+Your+Build+Tool.
Edit: I also updated the outdated wiki page you likely got this from (http://docs.codehaus.org/display/GROOVY/Compiling+With+Maven2).

Related Links

Maven - How to build a dependency project
How to make maven consider JavaFX as a part of JRE
Maven plugin prefix resolution doesn't seem to work as expected
Javascript and CSS files combining in Maven build WITHOUT compression, minification etc
Run TestNG single test from one Group
TinyRadius maven repository
Dependency downloaded from Maven Central is free from Malware?
How to use the same target platform multiple sub-projects in Tycho
Maven Grails web.xml
Can I make a Maven profile add webResources to a war and still add non-profiled webResources?
HTTP Status 409 - The target deployment path […] does not match the POM's expected path prefix
Maven command to go back to previous day snapshot
Maven site on multi module project could not resolve dependency
Glassfish Maven Deploy Plugin - Deployment Failure
zmq failed when running unit test in Intellij IDEA with Maven
How Can I Distribute Jetty With My WAR Using Maven?

Categories

HOME
yii2
pdf
openlayers
path-finding
onedrive
spagobi
sharepoint-designer
gps
fingerprint
onelogin
autotools
node-notifier
dacpac
gorm
rascal
quicklook
resize
jplayer
usergrid
windows-phone-7
iron-router
saxon
aurigma
ab-testing
nhibernate-envers
lucene.net
visjs
object-detection
physics-engine
accessor
mustache.php
language-agnostic
android-widget
opennlp
spark-jobserver
uninstall
c++-amp
procdump
skia
google-rich-snippets
stormpath
javascriptcore
.net-4.0
scorm2004
pim
usbserial
android-kernel
gammu
rotational-matrices
atl
abstract-class
greenrobot-eventbus
squib
particles.js
avro4s
grid.mvc
convertapi
carrot
np-complete
sonarlint-vs
google-feed-api
py2app
merge-conflict-resolution
lttng
blackberry-10
hover-over
tform
netmq
iad
intel-fortran
comobject
citrus-pay
drawbitmap
riak-cs
appfabric-cache
graph-drawing
skos
tween
nsbutton
zend-route
typeof
transcoding
stxxl
html5-notifications
listings
easy-install
shellexecute
ember-app-kit
anonymous-methods
gil
manchester-syntax
jspinclude
onsubmit
nsobject
xdomainrequest
lang
.nettiers
infrastructure
fixed-width
aquaticprime

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App