18

Here is the scenario:

Two Maven 3 project builds.

Build 1 has snapshot jars that get deployed to Nexus.

Build 2 has dependencies on the snapshots, referenced like 1.0.0-SNAPSHOT, that gets packaged up and zipped up using the mvn clean package assembly:single command.

The issue that we run into: Occasionally when the assembly is being created, the MANIFEST file for the jar will sometimes say some.jar.1.0.0-SNAPSHOT and sometimes it will say some.jar.1.0.0-datetime stamp, thus causing class not defined errors.

Is there a way to prevent this naming issue in the manifest file?

--edit--

Further research has discovered the following:

"If the snapshot was resolved from a repo then it will be timestamped, if it came from the reactor or local repo, then it will be -SNAPSHOT. The plugin calls into the maven resolution logic so this is core maven behavior. "

This is the exact issue that is being run into. The 2nd build manifest file always has an entry of ./lib/Framework-1.0.0-SNAPSHOT.jar where as the actual jar file name changes between ./lib/Framework-1.0.0-SNAPSHOT.jar and ./lib/Framework-1.0.0-timestamp.jar based on the quote above.

Thaldin
  • 283
  • 3
  • 15
  • [This](http://stackoverflow.com/questions/2516860/maven-how-to-create-assembly-with-snapshot-artifacts-without-timestamps-file-na) might help, it describes setting outputfilenamemapping to make file names consistent in snapshots. – prunge May 10 '12 at 04:46
  • 1
    How is the manifest of the SNAPSHOT generated and how is it configured to produce this information? Furthermore why is mvn clean package assembly:single called and not simply mvn clean package cause package will call the configured assembly-plugin. – khmarbaise May 10 '12 at 08:25
  • There is no manifest for the SNAPSHOT itself. The manifest with the issue is in the 2nd build. And with some help from a co-worker, we found this `If the snapshot was resolved from a repo then it will be timestamped, if it came from the reactor or local repo, then it will be -SNAPSHOT. The plugin calls into the maven resolution logic so this is core maven behavior.` This is the exact issue I am having, I just need to get around this. As to why package assembly:single is being called, well that's because we are new to maven as a whole. – Thaldin May 10 '12 at 16:16

5 Answers5

9

In <dependencySet> you need to set <outputFileNameMapping>${artifact.artifactId}-${artifact.baseVersion}.${artifact.extension}</outputFileNameMapping>

for example:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
  <id>appserverB</id>
  <formats>
    <format>zip</format>
  </formats>
  <dependencySets>
    <dependencySet>
      <outputDirectory>/lib</outputDirectory>
      <outputFileNameMapping>${artifact.artifactId}-${artifact.baseVersion}.${artifact.extension}</outputFileNameMapping>
      <includes>
        <include>application:logging</include>
        <include>application:core</include>
        <include>application:utils</include>
        <include>application:appserverB</include>
      </includes>
    </dependencySet>
  </dependencySets>
</assembly>

If you are using one of the built-in assembly descriptors you will need to replicate it for your self and add in the outputFileNameMapping entry yourself

Stephen Connolly
  • 13,872
  • 6
  • 41
  • 63
3

For people who use maven-jar-plugin to create the artifact which is then packed by the maven-assembly-plugin and you still see timestamps in the classpath in artifact names, you can disable that by setting useUniqueVersions=false, as follows:

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${maven-jar-plugin.version}</version>
<configuration>
    <archive>
        <manifest>
            <addClasspath>true</addClasspath>
            <classpathPrefix>${project.build.finalName}.lib/</classpathPrefix>
            <mainClass>com.nate.Application</mainClass>
            <!-- To force the use of '-SNAPSHOT' version naming, simply disable the <useUniqueVersions>  -->
            <useUniqueVersions>false</useUniqueVersions>
        </manifest>
        <manifestEntries>
            <buildTime>${maven.timestamp}</buildTime>
        </manifestEntries>
    </archive>
</configuration>
Tomask
  • 2,344
  • 3
  • 27
  • 37
2

use <useBaseVersion>false</useBaseVersion>, when you need copy dependencies. For example :

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.8</version>
                    <executions>
                        <execution>
                            <id>copy</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>${project.build.directory}</outputDirectory>
                                <useBaseVersion>false</useBaseVersion>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
znlyj
  • 1,109
  • 3
  • 14
  • 34
0

For those who run into this and see the answer from Stephen Connolly but still end up having exceptions, this might be due to the fact that some dependencies have classifiers in their names. Then you'll have to adapt the pattern to use the dashClassifier as an optional value:

<outputFileNameMapping>${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension}</outputFileNameMapping>

This will work even if the dependecy used does not have a classifier.

See the documentation for the assembly plugin for further details.

-1

<useBaseVersion>false</useBaseVersion> Did the trick for me. I just switched to a SNAPSHOT branch and it was including the timestamps.

Major advantage when using snapshots is one can refer to the actual date/time the snapshot was build.

siik
  • 1