mavenmaven-dependency-pluginmaven-jar-plugin

Maven archiver uses unlocked snapshots in classpath, but copy-dependencies copy locked snapshots


I am trying to use the maven-jar-plugin and maven-dependency-plugin to create an runnable "bundle" of my application. It works fine in most cases, but when I have a snapshot in the dependency hierarchy, the copy-dependencies goals seems to translate the snapshot-dependencies into locked snapshots (snapshots with timestamp)

However, addClasspath from archiver-plugin does not translate snapshot dependencies:

so I can't run the application.

I can't find a way to tell the copy-dependencies to not translate SNAPSHOTs or one to tell the archiver-plugin to translate SNAPSHOTs.

Here is the relevant snippet of the pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>          
    <artifactId>maven-dependency-plugin</artifactId>           
    <version>2.5.1</version>                  
    <executions>
        <execution>
            <id>copy-libs</id>
            <phase>package</phase>    
            <goals>
                <goal>copy-dependencies</goal>                          
            </goals>
            <configuration>
                <excludeScope>provided</excludeScope>
                <outputDirectory>${package.dest}/lib</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <configuration>
        <outputDirectory>${package.dest}</outputDirectory>
        <archive>
            <manifest>
                <addClasspath>true</addClasspath>
                <classpathPrefix>lib/</classpathPrefix>
                <mainClass>${main.class}</mainClass>
            </manifest>
        </archive>
        </configuration>
</plugin>

Solution

  • A new option (useBaseVersion) in maven-dependency-plugin 2.6 can fix this. So you need at least version 2.6.

    Note: I needed the useBaseVersion option set to false, as my problem seems to be the opposite of the original question. So the original version probably requires useBaseVersion is set to true, which is the default value.

    Below is an example on how to change the version number and set useBaseVersion to false in the pom:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>          
        <artifactId>maven-dependency-plugin</artifactId>
        <!-- need at least 2.6 for useBaseVersion-->           
        <version>2.6</version>                  
        <executions>
            <execution>
                <id>copy-libs</id>
                <phase>package</phase>
                <goals>
                    <goal>copy-dependencies</goal>                          
                </goals>
                <configuration>
                    <excludeScope>provided</excludeScope>
                    <outputDirectory>${package.dest}/lib</outputDirectory>
    
                    <!-- useBaseVersion=false makes the jar names match those 
                         that maven-jar-plugin puts in the manifest classpath -->
                    <useBaseVersion>false</useBaseVersion>
                </configuration>
            </execution>                    
        </executions>
    </plugin>