Question

In my ant build, I am using maven-ant-tasks to pull dependencies for my project. The build is relatively complicated and moves/manipulates different artifacts in different places. To make my life easier, I want to remove the maven version labels from my dependencies within my ant script. The maven-ant documentation says that we can use the versionsId property of the dependencies task to accomplish this but I am not sure how to do it in ant.

The relevant part of my build is

 <artifact:pom id="mypom" file="pom.xml"/>
 <artifact:dependencies pathId="dep.classpath" filesetId="dep.fileset" pomRefId="mypom" useScope="compile" settingsFile="${maven.home}\conf\settings.xml" versionsId="dep.versions"/>

 <copy todir="${lib.dir}" flatten="true" overwrite="true">
    <fileset refid="${dep.fileset}"/>
 </copy>

After this call, the dep.versions variable holds a semi-colon separated list of all the version labels. However, I'm not sure how to remove labels in a nice/clean way.

Thanks

Was it helpful?

Solution

Ok, guys, here's how I solved this

Maven has a custom mapper that is distributed with the maven-ant-tasks that will remove the version labels. You can pass in the versionIds variable from the dependencies tag.

<artifact:pom id="mypom" file="pom.xml"/>
<artifact:dependencies pathId="dep.classpath" filesetId="dep.fileset" pomRefId="mypom" useScope="compile" settingsFile="${maven.home}\conf\settings.xml" versionsId="dep.versions"/>

<copy todir="${lib.dir}" flatten="true" overwrite="true">
  <fileset refid="${dep.fileset}"/>
  <mapper classname="org.apache.maven.artifact.ant.VersionMapper" from="${dep.versions}" to="flatten" />
</copy>

If you didn't install the maven-ant-tasks in ANT_HOME/lib, you will have to define the classpath on the mapper as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top