Cuga
Cuga

Reputation: 17904

How to run build twice so that I can get two artifacts using different dependencies?

I've got a Maven project and we want to build two separate jars, one containing 32-bit libraries and one containing 64-bit libraries.

Our current build will produce either 32 or 64-bit artifacts depending on the operating system on which the build is run.

An overview of how we're currently set up:

    <properties>
            <env.arch>${sun.arch.data.model}</env.arch>
    </properties>

    <build>
    <pluginManagement>

    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                    <id>copy-native</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                    <artifactItems>
                    <artifactItem>
                        <groupId>artifact-for-${env.arch}</groupId>
                        <artifactId>artifact.name</artifactId>
                    </artifactItem>
                        ...

                   <plugin>
                       <artifactId>maven-jar-plugin</artifactId>
                       <executions>
                           <execution>
                               <phase>package</phase>
                           </execution>
                       </executions>

So what it's doing is copying the dependencies that match the value of our property for ${env.arch}, then building the jar using the maven-jar-plugin.

What we need to be able to do is produce 2 jars from one build... one containing the 32 bit dependencies and one containing the 64 bit dependencies.

Can anyone offer any guidance to how we can get this done?

Thanks

Upvotes: 1

Views: 1486

Answers (1)

J&#246;rn Horstmann
J&#246;rn Horstmann

Reputation: 34014

This can be done by specifying the dependencies in profiles like in this answer. You would have to build your project two times though to create both artifacts. You should probably also configure the jar plugin per profile to give different classifiers to the artifacts.

You could also just set a property in the profiles ant use this later in the dependency section instead of the environment variable.

You can also activate the profiles based on the architecture of the current system, to have a working default case:

<profile>
    <activation>
        <os>
            <arch>x86</arch>
        </os>
    </activation>
    ...
</profile>

All activation options are described on this page.

Upvotes: 2

Related Questions