Reputation: 19443
I have a product that contains a Jar file in its distribution and I have created a pom.xml that uses the install-file mojo to install the Jar into the local repository. So the user unpacks my zip file and types "mvn install" and everything works.
My problem is I have a second Jar file that I would also like to install using the same pom.xml, but this Jar file is optional and may or may not be present (the Jar file is downloaded separately by the user and placed in the same directory). I have tried install-file and also build-helper:attach-artifact and can't figure out how to do this within a single POM. I'm happy to have the user type some different command to install this Jar file, or have it work with "mvn install".
Upvotes: 0
Views: 168
Reputation: 52645
One possibility is to use a profile, which gets activated based on the existence of the second jar. This profile can be used to attach an additional artifact using the build helper maven plugin goal that you have referred above. Something like this...
<project>
...
<profiles>
<profile>
<id>second-jar</id>
<activation>
<file>
<exists>${basedir}/location/of/second.jar</exists>
</file>
</activation>
<build>
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>second</file>
<type>jar</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Upvotes: 1