Maven 程序集插件无论我做什么都提示没有文件

标签 maven maven-assembly-plugin jar-with-dependencies

我的情况与 Add jar-with-dependencies artifact from other Maven module 类似,但是建议的解决方案对我不起作用。我已经尝试同时使用 moduleSetsdependencySets .所以我们开始:
介绍:
我有一个多模块 Maven 项目:

parent
|
+-myProject
|
+-myProjectTests
我希望 myProjectTests 有 jar-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 做到这一点?

最佳答案

原来这是一个已知的 maven 错误 - 当子模块没有聚合器项目作为其父级时,程序集插件无法正常工作 - MASSEMBLY-600 .看起来我将不得不使用直接文件依赖项。

关于Maven 程序集插件无论我做什么都提示没有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19772444/

相关文章:

maven - docker 构建所需的敏感信息

maven-2 - 使用 Maven 创建一个 zip 文件,其中包含具有依赖关系的可执行 jar

java - 多模块项目的 Maven 组装插件入门

java - 如何在 Eclipse 中调试 Maven Surefire 测试

来自 Maven 的 Java OpenCV

Maven 程序集插件未在解压缩的依赖项集上应用 fileMode

deployment - 为 javafx 应用程序创建一个 bundle jar

maven - 使用 ansible maven_artifact 获取包含依赖项的 jar

java - maven web项目在eclipse(tomcat 7)运行报错:error:Cannot invoke Tomcat manager: Software caused connection abort: socket write error