16

我有一个多模块 maven 项目,我正在尝试让程序集插件的模块集源部分工作。

我有模块“ module_parent ”、“ module_a ”和“ module_assembly ”。

module_amodule_assemblymodule_parent的孩子。

module_assembly声明了对module_a的 pom 依赖。

module_assmebly有组装插件,其中的 assembly.xml 看起来像:

<?xml version="1.0"?>
<assembly>
  <id>bin</id>
  <formats>
    <format>zip</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <moduleSets>
    <moduleSet>
      <useAllReactorProjects>true</useAllReactorProjects>
      <includes>
        <include>com.mystuff:module_a</include>
      </includes>
      <sources>
        <fileSets>
          <fileSet>
            <outputDirectory>/</outputDirectory>
            <excludes>
              <exclude>**/target/**</exclude>
            </excludes>
            <directory>/</directory>
          </fileSet>
        </fileSets>
      </sources>
    </moduleSet>
  </moduleSets>
</assembly> <!-- -->

对于module_a,我在module_assembly 中有一个明确的依赖关系。module_assembly 的 pom 中的依赖项如下所示:

<dependencies>
    <dependency>
        <groupId>com.mystuff</groupId>
        <artifactId>module_a</artifactId>
        <version>1.0</version>
        <type>pom</type>
    </dependency>
</dependencies>

我从打开调试的 mvn 包中得到的错误是:

[DEBUG] All known ContainerDescritporHandler components: [metaInf-services, plexus, metaInf-spring, file-aggregator]
[DEBUG] No dependency sets specified.
[WARNING] The following patterns were never triggered in this artifact inclusion filter:
o  'com.mystuff:module_a'

[DEBUG] Cannot find ArtifactResolver with hint: project-cache-aware
org.codehaus.plexus.component.repository.exception.ComponentLookupException: java.util.NoSuchElementException
      role: org.apache.maven.artifact.resolver.ArtifactResolver
  roleHint: project-cache-aware
        at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:257)
        at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:233)
        at
  <snip>
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: java.util.NoSuchElementException
        at java.util.Collections$EmptyIterator.next(Collections.java:3006)
        at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:253)
        ... 43 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
<snip>
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2:single (make-assembly) on project apm-server-distribution: Failed to create assembly: Error creating assembly archive bin: You must set at least one file. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2:single (make-assembly) on project apm-server-distribution: Failed to create assembly: Error creating assembly archive bin: You must set at least one file.

我认为主要问题是这条警告线:

[WARNING] The following patterns were never triggered in this artifact inclusion filter:
    o  'com.mystuff:module_a'

我该如何纠正?

4

4 回答 4

15

如果 module_assembly 没有对您的模块的子引用,则它不算作模块。注意这里的内容仅指儿童:http ://maven.apache.org/plugins/maven-assembly-plugin/advanced-module-set-topics.html

如果你想这样做,你需要使用一个dependencySet而不是一个moduleSet。

PS - 谢谢你的赏金!

于 2013-07-06T17:49:50.973 回答
2

我只是在调试程序集插件,因为我有类似的问题,我认为问题是<useAllReactorProjects>true</useAllReactorProjects>. 最重要的是,还有 tag <includeSubModules>,这可能是你想要的。

<assembly>
  <id>bin</id>
  <formats>
    <format>zip</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <moduleSets>
    <moduleSet>
      <useAllReactorProjects>false</useAllReactorProjects><!-- Or just don't remove this line -->
      <includeSubModules>true>
...
    </moduleSet>
  </moduleSets>
</assembly
于 2014-10-21T12:10:17.717 回答
2

它使用以下配置对我有用:

  <includeSubModules>false</includeSubModules>
  <useAllReactorProjects>true</useAllReactorProjects>
于 2016-10-19T09:05:30.810 回答
1

您尝试的方法不起作用,因为module_a不是 module_assembly 的子模块

以下是您可以做什么的一些想法:

  • 将相关文件包含到 jar 中(可能源插件有帮助)并使用dependencySet。
  • 更改模块结构,使module_assembly是父模块,module_parentmodule_a是子模块。当然,依赖结构保持原样。
  • 只需在程序集中使用指向另一个项目的相对路径的文件集(丑陋!)
于 2013-07-10T21:18:36.897 回答