Hello
I'm having trouble with a multi module project that I m working on.
I need a class path inside the manifest of the built jar (plugin maven jar and
configuration <addClasspath>true</addClasspath> in my parent pom defined in
pluginManagement).
The classpath is perfectly formatted when I'm running the project from the
parent pom, but when I'm running maven from one of the module the class path is
not well formatted: it add a version tag at the end of the name of the library
the module depends on.
Example:
.
|-- pom.xml
|
|-- test
| `-- pom.xml
`-- toto
`-- pom.xml
A module toto (packaging: jar, version: 0.1) dependending on an other module
test (packaging: jar, version: 0.1) both are called by the pom parent
(packaging: pom, version: 0.1) using <modules> and both are inheriting from him
(<parent><artifactId>parent</artifactId><groupId>com.edifixio.sample</groupId><version>0.1</version></parent>)=>
fully project inheritance and aggregation.
The parent pom.xml look likes:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.edifixio.sample</groupId>
<artifactId>parent</artifactId>
<version>0.1</version>
<packaging>pom</packaging>
<modules>
<module>toto</module>
<module>test</module>
</modules>
<build>
<finalName>${artifactId}</finalName>
<pluginManagement><plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${mainClass}</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<!-- use of the newest version of the plugin in
usual plugin repository -->
<executions>
<execution><!-- Copy yourself in
outputDirectory -->
<id>copy</id>
<phase>install</phase><!-- add this
step in install lifecycle -->
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>
${project.groupId}
</groupId>
<artifactId>
${project.artifactId}
</artifactId>
<version>
${project.version}
</version>
<overWrite>true</overWrite>
<type>
${project.packaging}
</type>
<destFileName>
${artifactId}.${project.packaging}
</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>
${projectOutput}
</outputDirectory>
</configuration>
</execution>
<execution><!-- Copy dependency of the
artefact in outputDirectory -->
<id>copy-dependencies</id>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<stripVersion>true</stripVersion>
<outputDirectory>
${projectOutput}
</outputDirectory>
<excludeScope>provided</excludeScope>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
The directory test contains a pom.xml :
<project>
<parent><!-- inherit from parent -->
<groupId>com.edifixio.sample</groupId>
<artifactId>parent</artifactId>
<version>0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>
com.edifixio.sample
</groupId>
<artifactId>test</artifactId>
</project>
The directory toto contains a pom.xml :
<project>
<parent><!-- inherit from parent -->
<groupId>com.edifixio.sample</groupId>
<artifactId>parent</artifactId>
<version>0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>
com.edifixio.sample
</groupId>
<artifactId>toto</artifactId>
<dependencies>
<dependency>
<groupId>
com.edifixio.sample
</groupId>
<artifactId>test</artifactId>
<version>0.1</version>
</dependency>
</dependencies>
<build> <!-- Normal build + call of maven-dependency-plugin defined in
the superPom -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
When I m packaging from the parent pom the classpath inside of the manifest of
toto.jar looks like:
Class-Path: test.jar
When I'm packaging from toto the classpath inside the manifest of toto.jar
looks like:
Class-Path: test-0.1.jar
I need to have a classpath that is perfectly predictable because I'm using
those in order to run some of those standalone jars, and I'm getting the
libraries they are depending on with maven-dependency-plugin and formatting
them with a certain name format (actually <stripVersion>true</stripVersion>
remove version tag) (mvn install). And so the classpath can't be resolved in
case the version tag is in the manifest classpath.
Is there anywhere to format the name of the libraries inside the class-path? I
know we can alter the directory where to find the library (with
<classpathPrefix>) but the name I can't find any information?
Thanks for your time.
Tomas
PS: In reality the project is much more complex (with generic poms) but it's
behaving just the same. I've reproduced the problem with this example.