[英]Maven jar plugin - Wrong Class-Path entry for SNAPSHOT dependency
I am using maven-jar-plugin
to build jar and maven-assembly-plugin
to put all dependencies next to the JAR
in lib/
directory. 我正在使用
maven-jar-plugin
构建jar和maven-assembly-plugin
,将所有依赖项放在lib/
目录中的JAR
旁边。
If I use snapshot dependency this project, the Class-Path entry points do different JAR
of that dependency, then the actual packaged one. 如果我使用此项目的快照依赖项,则Class-Path入口点会执行该依赖项的不同
JAR
,然后是实际打包的JAR
。
Here is an example: 这是一个例子:
<dependency>
<groupId>x.y.z</groupId>
<artifactId>artifact</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
JAR
that is packaged for that dependency inti lib
direcotyr is artifact-1.0-SNAPSHOT
but Class-Path
entry in main JAR
s manifest is lib/artifact-1.0-20170201.104414-8.jar
为该依赖项inti
lib
direcotyr打包的JAR
是artifact-1.0-SNAPSHOT
但主JAR
清单中的Class-Path
条目是lib/artifact-1.0-20170201.104414-8.jar
What is happening here and why? 这里发生了什么,为什么?
Thanks in advance. 提前致谢。
My assembly.xml 我的assembly.xml
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<useTransitiveDependencies>true</useTransitiveDependencies>
<outputDirectory>lib</outputDirectory>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
Plugins: 插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.2</version>
<executions>
<execution>
<id>assembly</id>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<finalName>${dist.name}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptor>${basedir}/assembly.xml</descriptor>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<manifestEntries>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
<outputDirectory>${dist.dir}</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
You have been hit by MJAR-156 , which is currently unresolved as of the latest 3.0.2. 您已被MJAR-156击中,目前尚未解决最新的3.0.2。 The core issue is with the downstream Maven Archiver library, most probably MSHARED-169 .
核心问题是下游的Maven Archiver库,很可能是MSHARED-169 。
You can workaround that quite easily by specifying Maven Archiver not to create unique versions for snapshots. 通过指定Maven Archiver不为快照创建唯一版本,您可以非常轻松地解决这个问题。 This is controlled by the parameter
useUniqueVersions
under the manifest configuration, which defaults to true
. 这由manifest配置下的参数
useUniqueVersions
控制,默认为true
。 As such, you can change the configuration of the Jar Plugin to: 因此,您可以将Jar插件的配置更改为:
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<useUniqueVersions>false</useUniqueVersions>
</manifest>
<!-- rest of configuration -->
</archive>
<outputDirectory>${dist.dir}</outputDirectory>
</configuration>
<!-- the executions -->
</plugin>
Note that version 2.3.1 of the Jar Plugin is quite old, you should consider updating to the latest 3.0.2. 请注意,Jar插件的2.3.1版本已经很老了,您应该考虑更新到最新的3.0.2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.