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

Difference in transitive dependencies after Maven upgrade 2.2.1 to 3.2.5
Is it possible to specify in a parent pom exactly where I want to deploy a site?
Tomcat deployement issue in a Maven
Ruta script in Maven - Decrement in no. of tags
Missing Paho dependency in IBM iot-java github Maven project
What's the recommended way of building ELKI's current development status?
Maven:Non-resolvable parent POM and 'parent.relativePath' points at wrong local POM
Integration testing Maven jar in a Jetty container
Why after compiling/building my AWS sdk jar is only 3kb?
maven exec plugin doesn't recognize cucumber test class
Remove empty parent XML tags using jaxb2 fluent builder
Failed to build multiple assemblies in maven. No assemby descriptor found
Maven site deploy logs filling with [WARNING] Required credentials to nexus 3
why am i not able to download any dependancy from maven?
Error in running a spring batch war file
gradle download all dependencies from maven repo

Categories

HOME
ibm-bluemix
mediawiki
smarty
session
routes
maven-3
jsrender
baqend
angular-ui-bootstrap
windows-server
swagger-ui
gnupg
metatrader4
quicklook
gz
event-handling
decimal
dynamics-crm-online
serverless-framework
facebook-page
flux
google-pagespeed
plunker
kryo
trading
opennlp
su
greendao
fifo
spring-mybatis
elasticsearch-net
saas
google-cloud-nl
file-rename
newline
skia
tinymce-4
calibre
cloud-code
wpf-controls
file-format
devextreme
qwerty
espeak
leading-zero
eclipse-scout
pdf-reactor
node-gyp
spring-security-kerberos
nxlog
thin
angular2-meteor
user-accounts
filepicker
jedis
pnotify
gabor-filter
setter
forever
abcpdf9
adxstudio-portals
fuzzy-search
markojs
superstack
itextpdf
separator
django-unittest
ionic
responsive-images
apache-commons-fileupload
sortedlist
key-management
dd
applescript-objc
document-classification
castle
fluentautomation
comexception
rtmfp
jboss-weld
concurrent-collections
intentservice
imdbpy
floating-point-precision
access-rights
batterylevel
jquery-knob
quickdialog
ocx
semantic-diff
libc++
qt-jambi
cinema-4d
site.master
fluent-interface
asp.net-mvc-areas
xsdobjectgen
asp.net-profiles
ncqrs
webkit.net
brewmp
defensive-programming
grid-system
.net-1.0
rtml

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