我有与Add jar-with-dependencies artifact from other Maven module类似的情况,但是建议的解决方案对我不起作用。我试过同时使用moduleSets
和dependencySets
。所以我们开始:
介绍:
我有一个多模块 Maven 项目:
parent
|
+-myProject
|
+-myProjectTests
我希望 myProjectTestsjar-with-dependencies
在其输出目录中由 myProject 生成,以运行集成测试等(我使用的框架需要运行实际的 jar)
父 pom.xml:
<project>
<groupId>myGroup</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<modules>
<module>myProject</module>
<module>myProjectTests</module>
</modules>
</project>
我的项目 pom.xml:
<project>
<groupId>myGroup</groupId>
<artifactId>myProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</plugins>
</project>
myProjectTests pom.xml:
<project>
<groupId>myGroup</groupId>
<artifactId>myProjectTests</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>myGroup</groupId>
<artifactId>myProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>prepareTests</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>prepare.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
准备.xml:
<assembly>
<id>prepareTests</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
?????
</assembly>
模块集:
如果我尝试指定moduleSets
????? 在我的 prepare.xml 中像这样:
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>myGroup:myProject</include>
</includes>
<binaries>
<attachmentClassifier>jar-with-dependencies</attachmentClassifier>
<unpack>false</unpack>
</binaries>
</moduleSet>
</moduleSets>
我得到这个输出:
[WARNING] The following patterns were never triggered in this artifact inclusion filter: o 'myGroup.myProject' [WARNING] The following patterns were never triggered in this artifact inclusion filter: o 'myGroup.myProject' [WARNING] NOTE: Currently, inclusion of module dependencies may produce unpredictable results if a version conflict occurs. [ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.4:single (prepareTests) on project myProjectTests: Failed to create assembly: Error creating assembly archive prepareTests: You must set at least one file. -> [Help 1]
我已经搜索了 maven 文档和互联网以寻找解决方案,并尝试了各种标志的许多不同组合,所有这些都具有相同的错误。
依赖集:
如果我dependencySets
在 ??????? 像这样:
<dependencySets>
<dependencySet>
<includes>
<include>myGroup:myProject:jar-with-dependencies:0.0.1-SNAPSHOT</include>
</includes>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
我明白了:
[WARNING] Cannot include project artifact: myGroup:myProjectTests:pom:0.0.1-SNAPSHOT; it doesn't have an associated file or directory. [WARNING] The following patterns were never triggered in this artifact inclusion filter: o 'myGroup:myProject:jar-with-dependencies:0.0.1-SNAPSHOT' [ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.4:single (prepareTests) on project myProjectTests: Failed to create assembly: Error creating assembly archive prepareTests: You must set at least one file. -> [Help 1]
同样,我尝试了许多不同的标志组合,并删除了jar-with-dependencies
分类器,但都没有效果。
在这两种情况下,调试日志中都没有任何有用的信息,我已经探索了调试日志建议的一些途径。
我想要的很简单——在打包阶段将 myProject 生成的 jar-with-dependencies 文件放入 myProjectTests 的输出目录中,理想情况下不使用直接文件路径。我如何让 Maven 做到这一点?