Maven 2.x Antrun Plugin

Problems with multiple antrun declarations in multiproject

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.0, 1.1
  • Fix Version/s: 1.4
  • Component/s: None
  • Labels:
    None
  • Environment:
    maven 2.0.4, antrun 1.0 & 1.1, jdk 1.5.0_06, windows xp
  • Number of attachments :
    0

Description

I'm using antrun in my project to create an IzPack installation. The plugin configuration is below.

When maven is run from the top-level project, the ant taskdef fails because it cannot find the IzPackTask class. However, when I run maven from the subproject itself, it works fine. Not sure if this is related to http://jira.codehaus.org/browse/MANTRUN-49. The error message from maven is at the bottom.

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-antrun-plugin</artifactId>
	<executions>
		<execution>
			<phase>package</phase>
			<configuration>
				<tasks>
					<taskdef name="izpack" classname="com.izforge.izpack.ant.IzPackTask"/>
					<izpack input="${project.build.directory}/classes/izPack.xml" output="${project.build.directory}/CorasTool-${coras.version}-installer.jar" basedir="${project.build.directory}"/>
				</tasks>
			</configuration>
			<goals>
				<goal>run</goal>
			</goals>
		</execution>
	</executions>
	<dependencies>
		<dependency>
			<groupId>izpack</groupId>
			<artifactId>standalone-compiler</artifactId>
			<version>3.8.0</version>
		</dependency>
	</dependencies>
</plugin>

[INFO] [antrun:run {execution: default}]
[INFO] Executing tasks
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error executing ant tasks

Embedded error: taskdef class com.izforge.izpack.ant.IzPackTask cannot be found
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Error executing ant tasks
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:559)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:475)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:454)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:306)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:273)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:140)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:256)
        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:585)
        at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
        at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
        at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
        at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error executing ant tasks
        at org.apache.maven.plugin.antrun.AbstractAntMojo.executeTasks(AbstractAntMojo.java:77)
        at org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:72)
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:412)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:534)
        ... 16 more
Caused by: taskdef class com.izforge.izpack.ant.IzPackTask cannot be found
        at org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java:483)
        at org.apache.tools.ant.taskdefs.Definer.execute(Definer.java:183)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
        at org.apache.tools.ant.Task.perform(Task.java:364)
        at org.apache.tools.ant.Target.execute(Target.java:341)
        at org.apache.maven.plugin.antrun.AbstractAntMojo.executeTasks(AbstractAntMojo.java:71)
        ... 19 more
Caused by: java.lang.ClassNotFoundException: com.izforge.izpack.ant.IzPackTask
        at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1166)
        at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1107)
        at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:977)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:242)
        at org.apache.tools.ant.taskdefs.Definer.addDefinition(Definer.java:457)
        ... 24 more

Issue Links

Activity

Hide
Alexey Kharlamov added a comment -

I have the same problem. Any progress since 06/May?

Show
Alexey Kharlamov added a comment - I have the same problem. Any progress since 06/May?
Hide
Binyan added a comment -

I'm fairly certain this is the issue I ran into. Any hope of getting an update on this issue, or a pointer where to start looking for a fix? Its obvious from MANTRUN-63 that the plugin's classpath is being resolved differently when a multi-project build and not a standalone build.

Show
Binyan added a comment - I'm fairly certain this is the issue I ran into. Any hope of getting an update on this issue, or a pointer where to start looking for a fix? Its obvious from MANTRUN-63 that the plugin's classpath is being resolved differently when a multi-project build and not a standalone build.
Hide
Filippos Slavik added a comment -

Well, I have the same problem and I finally have an explanation. The problem occurs in a multi-module projects where the antrun plugin is being used in more than one module.

In my case, let's say that my multi-module project has modules A and B. Both modules are using the antrun plugin, but only module B specifies an additional classpath for the antrun plugin. If I invoke the antrun plugin within module B everything works great but if I do that from the parent, then my build fails. This is because module A ran it's build cycle before B and for some reason the maven.plugin.classpath was not altered for the antrun plugin when running module B build (perhaps because it was already defined from module A).

Thanks

Show
Filippos Slavik added a comment - Well, I have the same problem and I finally have an explanation. The problem occurs in a multi-module projects where the antrun plugin is being used in more than one module. In my case, let's say that my multi-module project has modules A and B. Both modules are using the antrun plugin, but only module B specifies an additional classpath for the antrun plugin. If I invoke the antrun plugin within module B everything works great but if I do that from the parent, then my build fails. This is because module A ran it's build cycle before B and for some reason the maven.plugin.classpath was not altered for the antrun plugin when running module B build (perhaps because it was already defined from module A). Thanks
Hide
Elid OR added a comment -

Near one year later this bug isn't not fixed yet ...

A solution (not elegant) is to add your dependencies (in the dependencies of the antrun plugin section) in the pom.xml of the first module launched in the build order.
This allow all other projects to benefit of these dependencies.

Show
Elid OR added a comment - Near one year later this bug isn't not fixed yet ... A solution (not elegant) is to add your dependencies (in the dependencies of the antrun plugin section) in the pom.xml of the first module launched in the build order. This allow all other projects to benefit of these dependencies.
Hide
Filippos Slavik added a comment -

Give an unique <id> for each "execution" section of the antrun plugin in your pom's and let us know if this fixes the issue.

Show
Filippos Slavik added a comment - Give an unique <id> for each "execution" section of the antrun plugin in your pom's and let us know if this fixes the issue.
Hide
Elid OR added a comment -

There are multiple poms, one per module. And in each pom there is a antrun section. In each antrun section there could be multiple execution section, for me there is only one exection section in each antrun declaration. And I have set a unique Id for each execution but it doesn't now work. Only plugin classpath of the first antrun section of the first pom is used in all module of a multi project.

Show
Elid OR added a comment - There are multiple poms, one per module. And in each pom there is a antrun section. In each antrun section there could be multiple execution section, for me there is only one exection section in each antrun declaration. And I have set a unique Id for each execution but it doesn't now work. Only plugin classpath of the first antrun section of the first pom is used in all module of a multi project.
Hide
Brian Topping added a comment - - edited

I'm looking at my build and think I have found a lead. I don't know the solution yet. Can others look at their build and see if this sounds right?

The build I am having problems with this on has a parent POM. Both the child and parent POMs have separate antrun executions. Initially, when I would execute the child build, everything would work fine, including the parent executions. But in reactor, the child fails.

Then I took the dependency that seems to be getting lost in the child build and duplicated it to the (seemingly) unrelated antrun plugin configuration in the parent. Problem solved.

I think this configuration creates a circular dependency in my case, but it did solve the problem. Now, on to seeing what I can do with it. Maybe move the dependencies into the executions instead of at the global level.

UPDATE: For some reason, comments were not showing up when I posted this. Seems this is old news.

Show
Brian Topping added a comment - - edited I'm looking at my build and think I have found a lead. I don't know the solution yet. Can others look at their build and see if this sounds right? The build I am having problems with this on has a parent POM. Both the child and parent POMs have separate antrun executions. Initially, when I would execute the child build, everything would work fine, including the parent executions. But in reactor, the child fails. Then I took the dependency that seems to be getting lost in the child build and duplicated it to the (seemingly) unrelated antrun plugin configuration in the parent. Problem solved. I think this configuration creates a circular dependency in my case, but it did solve the problem. Now, on to seeing what I can do with it. Maybe move the dependencies into the executions instead of at the global level. UPDATE: For some reason, comments were not showing up when I posted this. Seems this is old news.
Hide
Patrick Vinograd added a comment -

Just ran into this issue. For those encountering the same problem, Filippos's suggestion does NOT work. All of my executions have unique id elements and this behavior still occurs.

Show
Patrick Vinograd added a comment - Just ran into this issue. For those encountering the same problem, Filippos's suggestion does NOT work. All of my executions have unique id elements and this behavior still occurs.
Hide
Steinar Bang added a comment -

I encountered this issue when using the replaceregexp task. To make it work I had to put the following inside the <plugin> def for maven-antrun-plugin:
<dependencies>
<dependency>
<!-- Pulls in a JAR used by the replaceregexp optional Ant task -->
<groupId>ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.6.5</version>
</dependency>
</dependencies>
(put it between the <executions> end tag and the <plugin> end tag).

When I tried running this project as a module in a multi-module product the use of replaceregexp failed because it could not be found on the classpath.

The workaround I did was (as indicated in a different comment) to add the <dependency> setting to the maven-antrun-plugin config of a module that was built before the failing module (even though that maven-antrun-plugin config didn't have any tasks needing it). Then I could build from the top pom without failure.

Show
Steinar Bang added a comment - I encountered this issue when using the replaceregexp task. To make it work I had to put the following inside the <plugin> def for maven-antrun-plugin: <dependencies> <dependency> <!-- Pulls in a JAR used by the replaceregexp optional Ant task --> <groupId>ant</groupId> <artifactId>ant-nodeps</artifactId> <version>1.6.5</version> </dependency> </dependencies> (put it between the <executions> end tag and the <plugin> end tag). When I tried running this project as a module in a multi-module product the use of replaceregexp failed because it could not be found on the classpath. The workaround I did was (as indicated in a different comment) to add the <dependency> setting to the maven-antrun-plugin config of a module that was built before the failing module (even though that maven-antrun-plugin config didn't have any tasks needing it). Then I could build from the top pom without failure.
Hide
gotama added a comment -

Steinar - THANK YOU for the workaround! OMG I was going nuts for 2 days trying to figure this out. I figured it was a bug. I was simply trying to use Ant to scp some files and discovered the same - that on the module itself, it works but when exec from a parent POM on a multi-module project, the 'scp' fails. I added:

<dependencies>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-optional</artifactId>
<version>1.5.3-1</version>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.6.5</version>
</dependency>
</dependencies>

to the ant plugin for the first executing module in the multi-module project and when the last module was exec'd w/ the 'scp' command, all worked ok.

OK, so this bug is 2 years old and still causing pain. Whats the status on getting this fixed? Any interest? Thanks.

Show
gotama added a comment - Steinar - THANK YOU for the workaround! OMG I was going nuts for 2 days trying to figure this out. I figured it was a bug. I was simply trying to use Ant to scp some files and discovered the same - that on the module itself, it works but when exec from a parent POM on a multi-module project, the 'scp' fails. I added: <dependencies> <dependency> <groupId>ant</groupId> <artifactId>ant-optional</artifactId> <version>1.5.3-1</version> </dependency> <dependency> <groupId>ant</groupId> <artifactId>ant-jsch</artifactId> <version>1.6.5</version> </dependency> </dependencies> to the ant plugin for the first executing module in the multi-module project and when the last module was exec'd w/ the 'scp' command, all worked ok. OK, so this bug is 2 years old and still causing pain. Whats the status on getting this fixed? Any interest? Thanks.
Hide
bastian kaempfe added a comment - - edited

still got the same problem.

Show
bastian kaempfe added a comment - - edited still got the same problem.
Hide
Anders Li added a comment -

Using "classpathref" of taskdef to specify the classpath in which your ant task is.

<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>JPA Enhance</id>
<phase>process-classes</phase>
<configuration>
<tasks>
<!-- "classpathref" will make the 'ANT' task found when launching this project build from parent module. -->
<taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask" classpathref="maven.compile.classpath"/>

<openjpac addDefaultConstructor="true" enforcePropertyRestrictions="true" tmpClassLoader="false">
<classpath refid="maven.compile.classpath"/>
<fileset dir="./src/main/java">
<include name="*/authentication/db/.java"/>
</fileset>
<config propertiesFile="./src/main/resources/META-INF/openjpa.xml"/>
</openjpac>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

Show
Anders Li added a comment - Using "classpathref" of taskdef to specify the classpath in which your ant task is. <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>JPA Enhance</id> <phase>process-classes</phase> <configuration> <tasks> <!-- "classpathref" will make the 'ANT' task found when launching this project build from parent module. --> <taskdef name="openjpac" classname="org.apache.openjpa.ant.PCEnhancerTask" classpathref="maven.compile.classpath"/> <openjpac addDefaultConstructor="true" enforcePropertyRestrictions="true" tmpClassLoader="false"> <classpath refid="maven.compile.classpath"/> <fileset dir="./src/main/java"> <include name="*/authentication/db/.java"/> </fileset> <config propertiesFile="./src/main/resources/META-INF/openjpa.xml"/> </openjpac> </tasks> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin>
Hide
Aaron Pieper added a comment -

I was able to work around this issue by moving the antrun plugin dependencies out to the project level, and scoping them as "provided". It's kind of a messy fix, but it at least keeps the dependencies in the correct pom.xml

Show
Aaron Pieper added a comment - I was able to work around this issue by moving the antrun plugin dependencies out to the project level, and scoping them as "provided". It's kind of a messy fix, but it at least keeps the dependencies in the correct pom.xml
Hide
Bas van der Bent added a comment - - edited

Thanks Anders and Aaron! That really helped me out.

As I run it:

<project>
<parent>
...
</parent>

<!-- Dependencies. -->
<dependencies>
<dependency>
....
</dependency>
<!-- http://jira.codehaus.org/browse/MANTRUN-51 -->
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
<!-- antrun uses a different version of ant -->
<exclusions>
<exclusion>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
</exclusions>
<scope>provided</scope>
</dependency>
</dependencies>
<profiles>

<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>test</id>
<phase>test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<!-- adds the ant-contrib tasks (if/then/else used below) -->
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.compile.classpath" />
...
etc

Show
Bas van der Bent added a comment - - edited Thanks Anders and Aaron! That really helped me out. As I run it: <project> <parent> ... </parent> <!-- Dependencies. --> <dependencies> <dependency> .... </dependency> <!-- http://jira.codehaus.org/browse/MANTRUN-51 --> <dependency> <groupId>ant-contrib</groupId> <artifactId>ant-contrib</artifactId> <version>1.0b3</version> <!-- antrun uses a different version of ant --> <exclusions> <exclusion> <groupId>ant</groupId> <artifactId>ant</artifactId> </exclusion> </exclusions> <scope>provided</scope> </dependency> </dependencies> <profiles> <build> <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <id>test</id> <phase>test</phase> <goals> <goal>run</goal> </goals> <configuration> <tasks> <!-- adds the ant-contrib tasks (if/then/else used below) --> <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.compile.classpath" /> ... etc
Hide
Florian Kolbe added a comment - - edited

Moving the dependency snippet to the build tag of the module did not help for me (mvn 2.0.9) but moving it to this snippet of the parent pom:

<build>
    <pluginManagement>
      <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.1</version>
          <dependencies>
            <dependency>
              <groupId>ant</groupId>
              <artifactId>ant-optional</artifactId>
              <version>1.5.3-1</version>
            </dependency>
          </dependencies>
        </plugin>
      </plugins>
    </pluginManagement>
Show
Florian Kolbe added a comment - - edited Moving the dependency snippet to the build tag of the module did not help for me (mvn 2.0.9) but moving it to this snippet of the parent pom:
<build>
    <pluginManagement>
      <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.1</version>
          <dependencies>
            <dependency>
              <groupId>ant</groupId>
              <artifactId>ant-optional</artifactId>
              <version>1.5.3-1</version>
            </dependency>
          </dependencies>
        </plugin>
      </plugins>
    </pluginManagement>
Hide
Oscar Hierro added a comment -

I just run into this issue and used Anders Li's workaround as it's the best solution IMO.

Shouldn't this have been fixed already after 3 years?

Show
Oscar Hierro added a comment - I just run into this issue and used Anders Li's workaround as it's the best solution IMO. Shouldn't this have been fixed already after 3 years?
Hide
Paul Gier added a comment -

This is an issue in Maven core and is fixed in Maven 3. For the antrun plugin, documentation should be added to the plugin site that shows how to deal with this problem, and then this issue can be closed.

Show
Paul Gier added a comment - This is an issue in Maven core and is fixed in Maven 3. For the antrun plugin, documentation should be added to the plugin site that shows how to deal with this problem, and then this issue can be closed.
Hide
Paul Gier added a comment -

Documentation about this issue was added to the site FAQ in r790402.
A note about it has also been added to the plugin wiki page

Show
Paul Gier added a comment - Documentation about this issue was added to the site FAQ in r790402. A note about it has also been added to the plugin wiki page

People

Vote (31)
Watch (34)

Dates

  • Created:
    Updated:
    Resolved: