Maven antrun: pass maven properties to ant - maven

I am trying to pass maven properties (defined through profiles) to a antrun execution:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<dependencies>
<!-- ... these are ok -->
</dependencies>
<executions>
<execution>
<configuration>
<target>
<property name="ant_destDir" value="${destDir}" />
<property name="ant_serverDeploy" value="${serverDeploy}" />
<property name="ant_deployDir" value="${deployDir}" />
<property name="ant_userDeploy" value="${userDeploy}" />
<property name="ant_passwordDeploy" value="${passwordDeploy}" />
<!-- correct task definitions for sshexec and scp -->
<sshexec host="${serverDeploy}" username="${userDeploy}"
password="${passwordDeploy}" trust="yes"
command="some command" />
<scp remoteTodir="${userDeploy}#${serverDeploy}:${destDir}"
password="${passwordDeploy}" trust="yes" sftp="true">
<fileset dir="${deployDir}" includes="*.jar" />
</scp>
<sshexec host="${serverDeploy}" username="${userDeploy}"
password="${passwordDeploy}" trust="yes"
command="some command" />
</target>
</configuration>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
The properties are defined in profiles to allow for deployment in different servers (I know it's not the best possible approach, but this is the way things are done here), like this:
<profile>
<id>aprofile</id>
<properties>
<property name="serverDeploy" value="somevalue" />
<property name="userDeploy" value="someuser" />
<property name="passwordDeploy" value="somepassword" />
<!-- and so on -->
</properties>
</profile>
My problem is that I can't get maven properties to work in ant plugin; I tried to add a <echoproperties> task in ant to see which properties I have and there is no trace of maven properties.
Is it possible to use maven defined properties or should I use another approach? Any suggestion is welcome.
Edit: I modified the script as per first answer, it still doesn't work

You can pass the properties by defining new Ant properties (using the property tag in your target within the configuration). So for example:
<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.test</groupId>
<artifactId>test-module</artifactId>
<name>test-module</name>
<version>SNAPSHOT</version>
<properties>
<my.custom.property>false</my.custom.property>
</properties>
<profiles>
<profile>
<id>customProfile</id>
<properties>
<my.custom.property>true</my.custom.property>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<configuration>
<target>
<property name="antProperty" value="${my.custom.property}"/>
<echo message="Custom Ant Property is: ${antProperty}"/>
<echoproperties />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
When I execute mvn compile on this pom the output is:
main:
[echo] Custom Ant Property is: false
[echoproperties] #Ant properties
[echoproperties] #Thu Aug 08 17:17:30 CEST 2013
[echoproperties] ant.project.name=maven-antrun-
[echoproperties] ant.version=Apache Ant(TM) version 1.8.2 compiled on December 20 2010
[echoproperties] antProperty=false
and when the command is mvn -PcustomProfile compile then the output is:
main:
[echo] Custom Ant Property is: true
[echoproperties] #Ant properties
[echoproperties] #Thu Aug 08 17:18:30 CEST 2013
[echoproperties] ant.project.name=maven-antrun-
[echoproperties] ant.version=Apache Ant(TM) version 1.8.2 compiled on December 20 2010
[echoproperties] antProperty=true
This works using maven 3.0.5.

Most properties are automatically passed along to ant, at least if you're running an inlined ant script. Some of the properties get renamed. I suggest running "mvn -X" and the antrun plugin prints a list of all the variable mappings into ant (things like basedir becomes project.basedir, etc.)

On the newer versions of maven you can just use:
<taskdef resource="net/sf/antcontrib/antcontrib.properties"
classpathref="maven.plugin.classpath" />
example:
<build>
....
<plugins>
....
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<taskdef resource="net/sf/antcontrib/antcontrib.properties"
classpathref="maven.plugin.classpath" />
<echo message="Project name from Maven: ${project.name}" />
</tasks>
</configuration>
</execution>
</executions>
</plugin>
....
</plugins>
....
</build>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
<exclusions>
<exclusion>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.6.5</version>
</dependency>
</dependencies>

Related

java.lang.NoClassDefFoundError: com.trueaccord.scalapb.GeneratedEnum with Gatling Maven Plugin

Using the latest OpenJDK 11.0.7 with the Gatling Maven Plugin is resulting in this compilation crash. I tried deleting the local Maven repository folders for Gatling, scala-lang, and scala-sbt and re-running a clean install. Below I've pasted my pom.xml. Can someone help to resolve this?
java.lang.ClassNotFoundException: com.trueaccord.scalapb.GeneratedEnum
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:766)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:1078)
... 31 common frames omitted
Wrapped by: java.lang.NoClassDefFoundError: com.trueaccord.scalapb.GeneratedEnum
at java.base/java.lang.ClassLoader.defineClassImpl(Native Method)
at java.base/java.lang.ClassLoader.defineClassInternal(ClassLoader.java:476)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:437)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:1110)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:898)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:806)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:764)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:1078)
at sbt.internal.inc.FileAnalysisStore$BinaryFileStore.<init>(FileAnalysisStore.scala:50)
at sbt.internal.inc.FileAnalysisStore$.binary(FileAnalysisStore.scala:36)
at io.gatling.compiler.ZincCompiler$.doCompile(ZincCompiler.scala:174)
at io.gatling.compiler.ZincCompiler$.delayedEndpoint$io$gatling$compiler$ZincCompiler$1(ZincCompiler.scala:216)
at io.gatling.compiler.ZincCompiler$delayedInit$body.apply(ZincCompiler.scala:39)
at scala.Function0.apply$mcV$sp(Function0.scala:39)
at scala.Function0.apply$mcV$sp$(Function0.scala:39)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
at scala.App.$anonfun$main$1$adapted(App.scala:80)
at scala.App$$Lambda$5/0000000000000000.apply(Unknown Source)
at scala.collection.immutable.List.foreach(List.scala:392)
at scala.App.main(App.scala:80)
at scala.App.main$(App.scala:78)
at io.gatling.compiler.ZincCompiler$.main(ZincCompiler.scala:39)
at io.gatling.compiler.ZincCompiler.main(ZincCompiler.scala)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at io.gatling.mojo.MainWithArgsInFile.runMain(MainWithArgsInFile.java:50)
at io.gatling.mojo.MainWithArgsInFile.main(MainWithArgsInFile.java:33)
My redacted pom.xml:
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>***</groupId>
<artifactId>****</artifactId>
<version>1.0</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<gatling.version>3.3.1</gatling.version>
<gatling-plugin.version>3.0.5</gatling-plugin.version>
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
<!-- <scala-maven-plugin.version>4.3.1</scala-maven-plugin.version> -->
</properties>
<dependencies>
<dependency>
<groupId>io.gatling.highcharts</groupId>
<artifactId>gatling-charts-highcharts</artifactId>
<version>${gatling.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testSourceDirectory>simulations</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>bash</executable>
<arguments>
<argument>run.sh</argument>
<argument>${env.NS}</argument> <!-- will be empty if running with services -->
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>${gatling-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- the name of the single Simulation class to run -->
<simulationClass>${env.SIMULATION}</simulationClass>
<runMultipleSimulations>false</runMultipleSimulations> <!-- if the plugin should run multiple simulations sequentially -->
<includes> <!-- include filters, see dedicated section below -->
<include></include>
</includes>
<excludes> <!-- exclude filters, see dedicated section below -->
<exclude></exclude>
</excludes>
<reportsOnly></reportsOnly> <!-- to only trigger generating HTML reports from the log file contained in folder parameter -->
<runDescription>****</runDescription> <!-- short text that will be displayed in the HTML reports -->
<failOnError>true</failOnError> <!-- report failure in case of assertion failure, typically to fail CI pipeline -->
<continueOnAssertionFailure>false</continueOnAssertionFailure> <!-- keep on executing multiple simulations even if one fails -->
<useOldJenkinsJUnitSupport>true</useOldJenkinsJUnitSupport> <!-- report results to Jenkins JUnit support (workaround until we manage to get Gatling support into Jenkins) -->
<!-- pass extra parameters to the Gatling JVM -->
<jvmArgs>
<jvmArg>-DIAM=${env.IAM}</jvmArg>
<jvmArg>-DStarterkitsDir=${env.STARTERKITS_DIR}</jvmArg>
<jvmArg>-DServicesDir=${env.SERVICES_DIR}</jvmArg>
<jvmArg>-DGROUP=${env.RESOURCE_GROUP}</jvmArg>
<jvmArg>-DGORG=${env.ORG_GUID}</jvmArg>
<jvmArg>-DSPACE=${env.SPACE_GUID}</jvmArg>
<jvmArg>-DURL=${env.URL}</jvmArg>
<jvmArg>-DUsers=${env.USERS}</jvmArg>
<jvmArg>-DDuration=${env.DURATION}</jvmArg>
</jvmArgs>
<overrideJvmArgs>false</overrideJvmArgs> <!-- if above option should override the defaults instead of replacing them -->
<propagateSystemProperties>true</propagateSystemProperties> <!-- if System properties from the maven JVM should be propagated to the Gatling forked one -->
<!-- pass extra parameters to the Compiler JVM -->
<compilerJvmArgs>
</compilerJvmArgs>
<!-- if above option should override the defaults instead of replacing them -->
<overrideCompilerJvmArgs>false</overrideCompilerJvmArgs>
<!-- extra options to be passed to scalac -->
<!-- <extraScalacOptions>
<extraScalacOption></extraScalacOption>
</extraScalacOptions> -->
<disableCompiler>false</disableCompiler> <!-- if compiler should be disabled, typically because another plugin has already compiled sources -->
<simulationsFolder>${project.basedir}/simulations</simulationsFolder> <!-- where the simulations to be compiled are located -->
<resourcesFolder>${project.basedir}</resourcesFolder> <!-- where the test resources are located -->
<resultsFolder>${project.basedir}/target/gatling</resultsFolder> <!-- where the simulation log and the HTML reports will be generated -->
</configuration>
</plugin>
</plugins>
</build>
</project>
There's nothing wrong with gatling-maven-plugin.
As I said in the issue you opened on our bug tracker, you most likely have some corrupted jars in your local maven repository.
Maven sometimes messes up when downloading jars and still installs the corrupted files in the local repository. The ClassLoader can't open the jars (jars are just zip files) and silently ignores them, causing NoClassDefFoundErrors at runtime.
It looks like the gatling-maven-plugin compilation is not working or something else is going on with it. I switched to using scala-maven-plugin and that compiles my simulation classes successfully.
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>${scala-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<jvmArgs>
<jvmArg>-Xss100M</jvmArg>
</jvmArgs>
<args>
<arg>-target:jvm-1.8</arg>
<arg>-deprecation</arg>
<arg>-feature</arg>
<arg>-unchecked</arg>
<arg>-language:implicitConversions</arg>
<arg>-language:postfixOps</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>

Wrapping Ant in Maven - JAVA_HOME points to the JRE but works with just Ant

I have an Ant project that builds just fine on its own. I'm now trying to wrap it in a Maven build that will kick off the Ant build using maven-antrun-plugin. When I do this the build fails and I get this error,
[ERROR] C:\Users\bobby\workspace\libraries\build-targets\common-targets.xml:170: Unable to find a javac compiler;
[ERROR] com.sun.tools.javac.Main is not on the classpath.
[ERROR] Perhaps JAVA_HOME does not point to the JDK.
[ERROR] It is currently set to "C:\Java\jdk1.8.0_65\jre"
There are a lot of SOF posts on this error but I feel like mine is unique since it only happens when I'm wrapping the Ant build in Maven i.e., I do not get this error on the same project when I just say $ ant build.
This is part of my pom.xml file
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>process-resources</phase>
<configuration>
<tasks>
<ant antfile="build.xml" target="build" />
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>add-jar</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>build/bin/myWarFile.war</file>
<type>war</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
My JAVA_HOME Environment Variable is set to C:\Java\jdk1.8.0_65.
The file that is mentioned in the error is from a library my work maintains where we keep all of our Jars. In that file here is what's on line 170
<target name="compile-src">
<!-- Compile source -->
<javac srcdir="${java.src.dir}"
destdir="${class.dir}"
debug="${debug.flag}"
deprecation="${deprecation.flag}"
nowarn="${warnings.flag}"
optimize="off"
source="${source.value}">
<classpath refid="compile.classpath"/>
</javac>
</target>
The line with source= is line 170.
It's a common issue. Try with this configuration:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
...
<!-- Add this dependency to your ant-run configuration -->
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
...
</plugin>
Maven uses Java's system property java.home, which is not the same as the environment variable JAVA_HOME, but it is using it to compute its java.home by tacking on the jre sub-directory, as witnessed. Consequently, stuff needed by Ant is simply not available in the jre directory.
However, this configuration ensures that Ant's plugin dependencies are correctly satisfied.
You need to point to JDK not JRE. Just remove ire and try.
It is currently set to "C:\Java\jdk1.8.0_65\jre"
And if your JDK is set - another workaround - Can you copy tools.jar from jdk lib to jre lib and see if it works.

What is a better way for checking for the existence of an environment variable in the Maven antrun plugin?

I’m using Maven 3.2.3. I have this for my ant run plugin …
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>20020829</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>create-dodeploy-file</id>
<phase>package</phase>
<configuration>
<target>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<property environment="env"/>
<if>
<isset property="env.JBOSS_HOME"/>
<then>
<echo file="${JBOSS_HOME}/standalone/deployments/${project.artifactId}.war.dodeploy" append="false" message="" />
</then>
</if>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Despite the fact I know $JBOSS_HOME is defined in my environment (I’m able to run
echo $JBOSS_HOME
from the same bash shell in which I run my Maven build), the “isset” directive always returns false. Is there a better way to test for the existence of an environment variable in the Antrun plugin?
A target also has the ability to perform its execution if (or unless) a property has been set. To make a target sense this property, you should add the if (or unless) attribute with the name of the property that the target should react to.
<target name="build-if" if="env.JBOSS_HOME"/>
<target name="build-unless" unless="env.JBOSS_HOME"/>

Define different value per profile for same Maven property

I'm facing a problem with maven property per profiles. I have two profiles, each one has the same property 'prop.key' with different values. When I call mvn clean package -PA -PB or mvn clean package -PB -PA both are using the same value 'B-1.0-SNAPSHOT'. I'm using maven 3.0.4.
Below my POM :
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.module</groupId>
<artifactId>test-module</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<prop.key>UNKNOWN</prop.key>
</properties>
<profiles>
<profile>
<id>A</id>
<properties>
<prop.key>A-${project.version}</prop.key>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>A</id>
<phase>package</phase>
<configuration>
<tasks name="a" description="a-desc">
<echo message="RUN A = ${prop.key}" level="info"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>B</id>
<properties>
<prop.key>B-${project.version}</prop.key>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>B</id>
<phase>package</phase>
<configuration>
<tasks name="b" description="b-desc">
<echo message="RUN B = ${prop.key}" level="info"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
I have found 'similar topic' but with opposite result!
Is it a bug or a feature of maven?
You can write
mvn package -PA,B
for short.
The result is the same:
[echo] RUN A = B-1.0-SNAPSHOT and
[echo] RUN B = B-1.0-SNAPSHOT
This is the correct behaviour of maven.
One property can only have one specific value per run. You can overwrite a "default value" with a version in a profile. But if you redefine it in two profiles and activate both, one of the profiles "wins".
It is not possible to have one value per profile for one and the same property. Profiles do not have their own variable scope. Properties are always global.
I would think you get this behavior because last parameter for profile gets picked.
Try
mvn clean package -PA,B
See Maven introduction to profiles.
Profiles can be explicitly specified using the -P CLI option.
This option takes an argument that is a comma-delimited list of
profile-ids to use. When this option is specified, no profiles other
than those specified in the option argument will be activated.
When you run mvn package -PA,B, maven will read both profiles A and B, and the properties from later one in the pom.xml file will take precedence (B is defined below A in pom.xml), result in <prop.key>B-${project.version}</prop.key> will be used.

How to get a list of all dependency JARs in a parameter?

I'm working on a plugin for Talend Open Studio; the component architecture of that platform needs that all external JARs are declared in a component-descriptor XML file in a form like:
<IMPORT MODULE="commons-collections-3.2.1.jar" NAME="commons-collections-3.2.1"
REQUIRED="true"/>
I use the Maven dependency plugins to manage all these external JARs
Is there a way to get all the dependency names in a list or something? This way can I be able to build the required strings (using an antcontrib task, perhaps), fill a ${parameter} and finally add it to XML file using maven-replacer-plugin?
The simplest solution is to use the maven-dependency-plugin via the buld-classpath goal. This goal can be given supplemental parameters to put the result into a file like:
mvn dependency:build-classpath -Dmdep.outputFile=classpath.out
Ok, I partly resolved this way that should works with some limitations:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
<exclusions>
<exclusion>
<groupId>ant</groupId>
<artifactId>ant</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>ant</groupId>
<artifactId>ant-nodeps</artifactId>
<version>1.6.5</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>package</phase>
<id>copy-resources</id>
<configuration>
<exportAntProperties>true</exportAntProperties>
<tasks>
<!-- add the ant tasks from ant-contrib -->
<taskdef resource="net/sf/antcontrib/antlib.xml" classpathref="maven.plugin.classpath"/>
<var name="import.set" value=""/>
<for param="file">
<path>
<fileset dir="${project.build.directory}" includes="*.jar"/>
</path>
<sequential>
<var name="basename" unset="true"/>
<basename file="#{file}" property="basename"/>
<var name="filenames" value="${basename}"/>
<var name="import.clause" value='<IMPORT MODULE="${filenames}" NAME="${filenames}" REQUIRED="true"/>'/>
<var name="import.set" value="${import.clause}${line.separator}${import.set}" />
</sequential>
</for>
<property name="import.jar" value="${import.set}"/>
<echo>${import.jar}</echo>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Still some problems: even if exportAntProperties is set to true, the property ${import.jar} is still not available outside ant taska in other maven goals, while if i switch to maven-antrun-plugin 1.7 version, a "Error executing ant tasks: org.apache.tools.ant.launch.Locator.fromJarURI(Ljava/lang/String;)Ljava/lang/String;" exception is thrown. Still no clues...

Resources