maven - 如何在不使用“硬”依赖项的情况下在程序集中包含另一个模块的构建输出?
问题描述
我的(非常简化的)Maven 项目,包括所需的输出文件如下所示:
.
│ pom.xml
├───db-delivery
│ │ assembly.xml
│ │ db-delivery-info.txt
│ │ pom.xml
│ └───target
│ db-delivery-1.0.0-SNAPSHOT.zip
└───delivery
│ assembly.xml
│ delivery-info.txt
│ pom.xml
└───target
delivery-1.0.0-SNAPSHOT.zip
的内容delivery-1.0.0-SNAPSHOT.zip
看起来像这样(db-delivery
ZIP 文件只包含db-delivery-info.txt
):
.
│ delivery-info.txt
└───db
db-delivery-info.txt
如果我执行mvn verify
一切都很好。但是由于 to 的依赖msa:delivery
,msa:db-delivery:zip
一些需要依赖解析的“快速” Maven 目标无法执行,例如mvn dependency:tree
or mvn org.basepom.maven:duplicate-finder-maven-plugin:check
。问题是,除非package
涉及阶段,否则反应堆中的 ZIP 文件db-delivery
不可用,这会导致Could not find artifact msa:db-delivery:zip:1.0.0-SNAPSHOT
目标在delivery
.
我试图将依赖类型从更改zip
为pom
. 这样,“快速”目标就起作用了,但是如果我mvn verify
再次执行“完整”构建(db-delivery-1.0.0-SNAPSHOT.pom
文件。
有没有办法在不直接依赖(类型)的情况下将 ZIP 工件db-delivery
放入程序集中?只要我确保模块是在之前构建的(例如依赖于 type ),必要的文件在需要时就可用,所以从技术上讲这应该是可能的。delivery
zip
db-delivery
delivery
pom
根(聚合器和父 POM):
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>msa</groupId>
<artifactId>root</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>delivery</module>
<module>db-delivery</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
模块交付
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>msa</groupId>
<artifactId>root</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>delivery</artifactId>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>msa</groupId>
<artifactId>db-delivery</artifactId>
<version>${project.version}</version>
<type>zip</type><!-- using pom makes `mvn dependency:tree` work but creates wrong ZIP file content -->
</dependency>
</dependencies>
</project>
<assembly>
<id>delivery-zip</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<file>
<source>delivery-info.txt</source>
</file>
</files>
<dependencySets>
<dependencySet>
<outputDirectory>db</outputDirectory>
<unpack>true</unpack>
<useProjectArtifact>false</useProjectArtifact>
<includes>
<include>msa:db-delivery</include>
</includes>
</dependencySet>
</dependencySets>
</assembly>
模块db-delivery
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>msa</groupId>
<artifactId>root</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>db-delivery</artifactId>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
<assembly>
<id>db-delivery-zip</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<file>
<source>db-delivery-info.txt</source>
</file>
</files>
</assembly>
解决方案
推荐阅读
- node.js - Firebase 云函数 - 错误:Reference.child 失败:第一个参数是无效路径
- ios - 无法执行文件“launchPackager.command”,因为您没有适当的访问权限
- class - Flutter:不要初始化类类型变量
- java - 如何在 Maven 中访问多个 repo?
- swift - 在代码“使用未解析的标识符 Firestore”中出现错误,但程序运行良好 SwiftUI
- c++ - Geeks for Geeks 问题中的分段错误 (SIGSEGV)
- apache-spark - PySpark 笔记本中的 Py4JJavaError 键错误
- python - 是否有一个 python 函数可以创建两个熊猫数据框列的转换表
- sql-server - 如何在 SQL Server 的 select 语句中将临时列添加到列列表中?
- unity3d - Unity dll 在编辑器中工作,但无法独立加载