You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Silvio Arcangeli <sa...@progress.com> on 2008/11/04 13:46:00 UTC

antrun plugin: inheriting external build file together with a pom

Hi all,

I'm trying to solve a puzzle which starts to look harder than I thought.

 

In my build platform I have project type that normally produces a jar
file, and in certain corner cases (for solving class loading issues) it
may have to produce also a second jar file if any class file is present
under a certain directory pattern.

 

First solution was to add a maven jar execution to my parent pom, but
that would always produce the "corner case" jar file also when it's
empty. I want to avoid this, as it would create confusion for all
"normal" cases, but couldn't find a way to avoid manifest-only jar files
using the maven jar plugin.

 

So I tried to solve it by replacing the maven jar with an ant task...
Since the "if" task is not available in maven (ant-contrib is not
included as far as I understood), I need to define a target if I want to
specify a conditional behavior, and this means that I cannot embed the
task directly in the pom file, and I'm forced to use an external build
file.

 

So I wrote my "build.xml" and called it from the pom. Everything works
fine if executed directly on the final project, but now I can't find a
way to move its execution in the parent pom and store "build.xml"
together with that pom file instead of having to store it somewhere in
the final project location...

 

Does anybody have any advice on how to solve it?

 

Thanks!

Silvio

 

p.s. here's my antrun execution:

 

      <plugin>

        <artifactId>maven-antrun-plugin</artifactId>

        <executions>

          <execution>

            <phase>package</phase>

            <configuration>

              <tasks>

                <property name="project_targetClasses"
value="${project.build.outputDirectory}"/>

                <property name="project_target"
value="${project.build.directory}"/>

                <property name="project_artifact"
value="${project.artifactId}"/>

                <property name="project_version"
value="${project.version}"/>

                <ant target="boot.fileset.jar"/>

              </tasks>

            </configuration>

            <goals>

              <goal>run</goal>

            </goals>

          </execution>

        </executions>

      </plugin>

 

And here's my build.xml:

 

<project name="My JAR file package" default="boot.fileset.jar">

            <fileset dir="${project_targetClasses}" id="boot.fileset"
includes="**/boot/*" />

 

            <target name="boot.fileset.checkExist">

                        <pathconvert refid="boot.fileset"
property="boot.fileset.notEmpty" setonempty="false" />

            </target>

 

            <target name="boot.fileset.jar"
depends="boot.fileset.checkExist" if="boot.fileset.notEmpty">

                        <jar
destfile="${project_target}/${project_artifact}-${project_version}-boot.
jar">

                                    <fileset refid="boot.fileset" />

                        </jar>

            </target>

</project>