我注意到maven-assembly-plugin不想在程序集jar中包含快照依赖项。这是设计还是我做错了。
<dependency>
<groupId>com.xxx.zzz</groupId>
<artifactId>projectname</artifactId>
<version>1.7.0-SNAPSHOT</version>
</dependency>
有这样的多个快照依赖项,所以我讨厌将它们显式地包含在汇编描述符中。
问题1: 有没有办法在捆绑中包含快照依赖项?
问题2: 你能帮忙弄清楚如何在组装的jar中包含所有依赖项(编译,测试,提供和运行时)。默认情况下,maven仅考虑运行时jar
以下是pom中的maven-assembly部分
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>${project.basedir}/assembly.xml</descriptor>
</descriptors>
<tarLongFileMode>gnu</tarLongFileMode>
<finalName>${project.artifactId}-${project.version}</finalName>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
这是程序集描述符文件
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>dist</id>
<includeBaseDirectory>true</includeBaseDirectory>
<formats>
<format>jar</format>
</formats>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<useTransitiveDependencies>true</useTransitiveDependencies>
<unpack>false</unpack>
<fileMode>0755</fileMode>
<directoryMode>0755</directoryMode>
<includes></includes>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<includes>
<include>database/**</include>
<include>deploy/**</include>
</includes>
<excludes>
<exclude>**/*.tmp</exclude
</excludes>
<directory>${project.basedir}</directory>
</fileSet>
</fileSets>
</assembly>
你可以请一些亮点吗?
答案 0 :(得分:1)
对于问题1,要包含当前版本的快照依赖项,请使用moduleSet
即,如果它们来自当前的反应堆。否则你将不得不构建它们并依赖于发布版本。
答案 1 :(得分:0)
找到了第二个问题的答案。感谢Bo Ni发布了这个博客:http://bosbluebluesky.blogspot.com/2012/11/maven-package-jar-file-include-all.html
我所要做的就是在多个依赖集部分中单独包含不同的范围
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<useTransitiveDependencies>true</useTransitiveDependencies>
<unpack>false</unpack>
<scope>runtime</scope>
<fileMode>0755</fileMode>
<directoryMode>0755</directoryMode>
<includes></includes>
</dependencySet>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<useTransitiveDependencies>true</useTransitiveDependencies>
<unpack>false</unpack>
<scope>compile</scope>
<fileMode>0755</fileMode>
<directoryMode>0755</directoryMode>
<includes></includes>
</dependencySet>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<useTransitiveDependencies>true</useTransitiveDependencies>
<unpack>false</unpack>
<scope>provided</scope>
<fileMode>0755</fileMode>
<directoryMode>0755</directoryMode>
<includes></includes>
</dependencySet>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<useProjectArtifact>false</useProjectArtifact>
<useTransitiveDependencies>true</useTransitiveDependencies>
<unpack>false</unpack>
<scope>test</scope>
<fileMode>0755</fileMode>
<directoryMode>0755</directoryMode>
<includes></includes>
</dependencySet>
</dependencySets>