【问题标题】:Maven - use assembly file and configuration from the parent projectMaven - 使用父项目中的程序集文件和配置
【发布时间】:2014-08-22 09:56:16
【问题描述】:

我有一个父项目,它定义了程序集插件的整个配置,包括 assembly.xml 文件(创建一个 tar.gz)。现在我想拥有多个可以使用父项目配置和父程序集文件的子项。

现在我尝试了不同的场景并且配置工作正常,但是我得到了在本地找不到程序集文件的错误。我想要实现的是不必在所有项目中一遍又一遍地配置和添加相同的文件。有没有办法实现这个目标?

【问题讨论】:

  • 在父级中定义 maven-assembly-plugin 的配置等没有意义,除非它是在 pluginManagement 块中定义的。
  • @khmarbaise 好的,所以我应该使用 pluginManagement 来定义行为?我的意思是,我想要实现的是不必在所有项目中一遍又一遍地配置和添加相同的文件
  • 如果您可以发布完整的 pom 文件或无法按预期工作的示例,将会很有帮助...

标签: java maven maven-3 maven-plugin maven-assembly-plugin


【解决方案1】:

您应该在所有子模块的 pom.xml 中禁用组装:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
    <skipAssembly>true</skipAssembly>
</configuration>
</plugin>

更常见的是,建议创建一个专用的子模块来配置组装插件,而不是在父 pom.xml 中配置组装插件

【讨论】:

  • 你能扩大第二个选择吗? (使用专用子模块进行组装)
  • 另外,如果我使用 skipAssembly,则不再创建预期的 tar 文件
  • 注意:不要在现有的父 pom.xml 上添加 !您应该将给定的配置插入到所有 SUB-MODULES 的 pom.xml
  • 是的,这就是我所做的。我得到Assemblies have been skipped per configuration of the skipAssembly parameter,如果我想安装,我得到预期的 tar 文件不存在
【解决方案2】:

我使用 maven-remote-resources-plugin 来共享程序集描述符。首先,创建一个单独的项目来保存您要共享的程序集描述符。

project-assemblies
  src
    main
      resources
        <your assembly descriptors, in any package structure you like>
  pom.xml

POM 的构建部分(假设这是项目 com.mycompany.project:project-assemblies):

<build>
  <plugins>
      <plugin>
          <artifactId>maven-remote-resources-plugin</artifactId>
          <executions>
              <execution>
                  <goals>
                      <goal>bundle</goal>
                  </goals>
              </execution>
          </executions>
          <configuration>
              <includes>
                  <include>**/*.xml</include>
              </includes>
          </configuration>
      </plugin>
   </plugins>
</build>

要从另一个项目中引用它,请将其添加到项目的 POM:

<properties>
  <shared.assemblies.dir>${project.build.directory}/assemblies</shared.assemblies.dir>
  <project-assemblies.version><yourAssemblyProjectVersion</project-assemblies.version>
</properties>

<!-- copy the assembly descriptors into this project -->
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-remote-resources-plugin</artifactId>
  <executions>
    <execution>
      <id>assemblies</id>
      <phase>initialize</phase>
      <goals>
        <goal>process</goal>
      </goals>
      <configuration>
        <resourceBundles>
          <resourceBundle>com.mycompany.project:project-assemblies:${project-assembly.version}</resourceBundle>
        </resourceBundles>
        <attached>false</attached>
        <outputDirectory>${shared.assemblies.dir}</outputDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>

设置为 false 意味着捆绑包的内容不会包含在最终的项目构建中。

<!-- Apply the retrieved assembly descriptor to this project -->
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-assembly-plugin</artifactId>
  <executions>
    <execution>
      <id>run-assembly</id>
      <phase>package</phase>
      <goals>
        <goal>single</goal>
      </goals>
      <configuration>
        <descriptors>
          <descriptor>${shared.assemblies.dir}/<pathToAssemblyDescriptor></descriptor>
        </descriptors>
        <!-- other config here -->
      </configuration>
    </execution>
  </executions>
</plugin>

像魅力一样工作。

【讨论】:

  • 不需要 maven-remote-resources-plugin 共享描述符,这可以在没有 read the documentation 的情况下完成。
【解决方案3】:

好吧,创建一个专用的子模块来配置组装插件,而不是在父 pom.xml 中配置组装插件

样品请参考:http://maven.apache.org/plugins/maven-assembly-plugin/examples/multimodule/module-binary-inclusion-simple.html

在这个示例中,它创建了一个名为:distribution 的子模块

这是一个很好的例子!祝你好运!

【讨论】:

    猜你喜欢
    • 2018-07-23
    • 2012-12-30
    • 1970-01-01
    • 2012-08-06
    • 1970-01-01
    • 1970-01-01
    • 2013-10-16
    • 2016-04-09
    • 1970-01-01
    相关资源
    最近更新 更多