[英]maven multimodule project: can I jar-with-dependencies?
我有一个maven项目,其中有一个主项目A以及模块B和C。孩子继承自A的pom。
A
|
|----B
| |----pom.xml
|
|----C
| |----pom.xml
|
|----pom.xml
它已经为所有模块构建了jar。 有没有办法在这些jar中包含依赖项? 例如,我得到B-1.0-with-dependencies.jar
和C-1.0-with-dependencies.jar
吗? 我尝试设置
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
在父pom中,它似乎什么也没做:构建成功,但是我得到了常规的,无依赖的jar。
我想避免在每个子pom中放入内容,因为实际上我有两个以上的模块。 我敢肯定有某种方法可以做到这一点,但似乎无法从Maven文档中解决。 谢谢!
这就是我的工作方式。
在聚合器/父pom中,我配置了:
<properties>
<skip.assembly>true</skip.assembly>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<skipAssembly>${skip.assembly}</skipAssembly>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
请注意skip.assembly
属性,默认情况下将其设置为true
。 这意味着该程序集将不会在父级上执行,这是有道理的,因为父级不提供任何代码(具有包装pom
)。
然后,在每个模块中,我仅配置以下内容:
<properties>
<skip.assembly>false</skip.assembly>
</properties>
这意味着在每个子模块中,将禁用跳过,并按照父级中的配置执行程序集。 此外,通过这种配置,您还可以轻松跳过某个模块的装配(如果需要)。
还请注意父级上的程序集配置,我在您提供的配置之上添加了一个execution
,以便在调用mvn clean package
(或mvn clean install
)时自动触发程序集插件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.