Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Environment:- ANT 1.6.5 (with bsh-2.0b4.jar in ANT_HOME/lib)
- JDK 1.5
-
Number of attachments :
Description
Hi,
In ANT, sometimes more than one artifact is generated from the same
build file (e.g. myapp.jar, myapp-client.jar, myapp-with-deps.jar).
If using the M2 plugin for ANT (currently 2.0.4), this would mean
we would need three POM's for the above 3 artifacts. However, in the
above case the 3 POM's would be almost identical.
So I have taken the following approach in order to have only one generic
POM:
pom.xml (with ANT tokens TOKEN...):
<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>be.steria.test</groupId>
<artifactId>TOKEN_ARTIFACTID</artifactId>
<packaging>TOKEN_PACKAGING</packaging>
<version>1.5-SNAPSHOT</version>
<description>Test artifact</description>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.9</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<distributionManagement>
<repository>
<id>repo_dev</id>
<url>scp://localhost/m2demo/repo_dev</url>
</repository>
</distributionManagement>
</project>
build.xml:
<project name="example-ant-using-m2-plugin" default="m2init"
xmlns:m="antlib:org.apache.maven.artifact.ant">
<macrodef name="create-pom">
<attribute name="pomRefId"/>
<attribute name="artifactId"/>
<attribute name="packaging" default="jar"/>
<sequential>
<!-- IMPORTANT : derived POM files must be generated in the same
folder as pom.xml, otherwise the paths, ... will be incorrect -->
<copy file="pom.xml" filtering="true"
toFile="pom-@
<filterchain>
<tokenfilter>
<replacestring from="TOKEN_ARTIFACTID"
to="@{artifactId}"/>
<replacestring from="TOKEN_PACKAGING"
to="@{packaging}"/>
</tokenfilter>
</filterchain>
</copy>
<m:pom id="@{pomRefId}
" file="pom-@
{pomRefId}.derived.xml"/>
</sequential>
</macrodef>
<target name="m2init">
<m:pom id="M2POM" file="pom.xml"/>
<!-- causes ClassCastException in macrodef 'create-pom' -->
<!-script language="beanshell"/->
<!-- create POM's on-the-fly (one for each artifact) -->
<create-pom pomRefId="M2POM_MYAPP" artifactId="myapp"/>
<create-pom pomRefId="M2POM_MYAPP_CLIENT" artifactId="myapp-client"/>
<create-pom pomRefId="M2POM_MYAPP_WITH_DEPS" artifactId="myapp-with-deps"/>
</target>
<target name="package" depends="m2init">
<!-- ... generate artifacts (pure ANT) ... -->
</target>
<target name="install" depends="package">
<m:install file="myapp.jar"
pomRefId="M2POM_MYAPP"/>
<m:install file="myapp-client.jar"
pomRefId="M2POM_MYAPP_CLIENT"/>
<m:install file="myapp-with-deps.jar"
pomRefId="M2POM_MYAPP_WITH_DEPS"/>
</target>
<target name="deploy">
<m:deploy file="myapp.jar"
pomRefId="M2POM_MYAPP"/>
<m:deploy file="myapp-client.jar"
pomRefId="M2POM_MYAPP_CLIENT"/>
<m:deploy file="myapp-with-deps.jar"
pomRefId="M2POM_MYAPP_WITH_DEPS"/>
</target>
</project>
Now if I execute the above, everything works fine, but if I add <script
language="beanshell"/> in the target 'm2init', then the following error
is generated on the first <create-pom> call:
"java.lang.ClassCastException: org.apache.maven.artifact.ant.Pom"
Regards,
Davy Toch
Hello Davy,
this problem might be due to Ant, not to Maven.
It looks like it Ant's bug 40238 which is fixed in Ant 1.7.
You can download Ant 1.7.0Beta2 from ant.apache.org to check whether this solves your issue.
Regards,
Antoine