【问题标题】:Maven assembly plugin complains about no files whatever I do无论我做什么,Maven 程序集插件都抱怨没有文件
【发布时间】:2013-11-04 16:36:53
【问题描述】:

我的情况与Add jar-with-dependencies artifact from other Maven module 类似,但是建议的解决方案对我不起作用。我试过同时使用moduleSetsdependencySets。所以我们开始:

简介:

我有一个多模块 maven 项目:

parent
|
+-myProject
|
+-myProjectTests

我希望 myProjectTests 在其输出目录中拥有由 myProject 生成的jar-with-dependencies,以便在其上运行集成测试等(我使用的框架需要一个实际的 jar 才能运行)

父 pom.xml

<project>
  <groupId>myGroup</groupId>
  <artifactId>parent</artifactId>
  <packaging>pom</packaging>
  
  <modules>
    <module>myProject</module>
    <module>myProjectTests</module>
  </modules>
</project>

myProject 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>

prepare.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 maven-assembly-plugin jar-with-dependencies


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-04-26
      • 2016-01-05
      • 2019-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-24
      • 2011-04-15
      相关资源
      最近更新 更多