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

时间:2013-11-04 16:36:54

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

我和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:

如果我尝试为?????指定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像这样:

<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这样做?

1 个答案:

答案 0 :(得分:8)

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