java - Maven 程序集插件目标“jar-with-dependencies”不包含来自子 pom 的 jar 文件
问题描述
我试图为我的问题找到一个合适的解决方案,但它看起来类似于以下一个maven 程序集,包括在最终 zip/tar 中的当前项目 jar。
一个项目的想法是有一个父 pom 和几个子 pom。当我从根级别执行“mvn assembly:single”命令时,我希望每个孩子都有“jar-with-dependencies”。
所以,到目前为止我得到了什么:
- 如果我一个一个地执行
mvn package
,mvn assembly:single
那么第一个将成功完成,第二个将警告不包含子项目。由于没有包含我的模块,因此我无法启动目标。 - 如果我执行
mvn package assembly:single
,则将创建具有所有依赖项的所需 jar,并且我能够启动目标。
我担心我错过了其中一个pom.xml
. 如果有人可以帮助我,我将不胜感激。我正在使用此示例在 GitHub 存储库上添加一个链接。
顺便说一句,我正在使用maven-assembly-plugin
版本3.1.0
提前谢谢你,我想,我需要买一本关于 Maven 的好书。
解决方案
关键是禁用父项目的程序集执行:可以通过组合<skipAssembly>
选项,profiles
节和properties
节来实现。
使用以下 pom 文件,它可以正常工作。
家长pom.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.slemarchand.samples.jarwithdependencies</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parent</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<skip.assembly>true</skip.assembly>
</properties>
<modules>
<module>child1</module>
<module>child2</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<skipAssembly>${skip.assembly}</skipAssembly>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles>
<profile>
<id>jar</id>
<activation>
<file>
<exists>${basedir}/src/main/java</exists>
</file>
</activation>
<properties>
<skip.assembly>false</skip.assembly>
</properties>
</profile>
</profiles>
</project>
孩子 1 pom.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.slemarchand.samples.jarwithdependencies</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>child1</artifactId>
<version>1.0-SNAPSHOT</version>
<name>child1</name>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>25.1-jre</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
</project>
孩子 2 pom.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.slemarchand.samples.jarwithdependencies</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>child2</artifactId>
<version>1.0-SNAPSHOT</version>
<name>child2</name>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
<build>
</build>
</project>
您可以在此处找到示例项目:https ://gitlab.com/slemarchand/jar-with-dependencies-multi-module-sample 。
推荐阅读
- macos - 架构 x86_64 的未定义符号:“_utimensat”,引用自:libHSdirectory-1.3.3.0.a(Posix.o) 中的 _cazW_info
- c# - 如何在表单之间传递登录数据
- docker - 如何在 Windows 10 上使用 docker-compose 挂载卷?
- python - 在python中获取嵌套字典的值
- sql - 获取每行查询的 30 天前数据
- if-statement - 如何在程序集中设置 If 然后
- c++ - 如何同时使用 window 的 visual studio 2017 和 mac 的 Xcode 10.2.1 处理同一个项目?
- ios - 如何在不捐赠意图或使用快捷方式的情况下利用 Siri 创建自定义对象?
- php - php html 表单有效的电子邮件检查和发布
- c - wireshark如何解释字节顺序?