Maven组件插件-包括子模块的依赖项? [英] Maven Assembly Plugin - Include Dependencies from Sub-Modules?

查看:123
本文介绍了Maven组件插件-包括子模块的依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为大型多模块项目设置程序集插件.现在的目标是将我所有的工件放入一个目录中.这是我的描述符:

    <assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>Install-Package</id>
<formats>
    <format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
    <dependencySet>
        <unpack>false</unpack>
        <scope>runtime</scope>
        <outputDirectory>dependencies</outputDirectory>
    </dependencySet>
</dependencySets>
<moduleSets>
    <moduleSet>
        <binaries>
            <unpack>false</unpack>
        </binaries>
    </moduleSet>
</moduleSets>

当前,这会将我所有的工件复制到Assembly目录.到目前为止,一切都很好.问题在于,依赖项文件夹仅包含主pom文件中列出的依赖项.有没有一种方法可以在程序集中包含子模块的依赖项,而不必在根pom中列出所有子模块? (将它们全部包含在root pom上会给子模块增加额外的未使用依赖性,如果它们是单独构建的.)

谢谢!

解决方案

问题在于依赖项文件夹仅包含主pom文件中列出的依赖项.

是的,这就是顶部" dependencySets的作用.

是否有一种方法可以在程序集中包含子模块的依赖项,而不必在根pom中列出所有子模块?

删除顶部" dependencySets,并在moduleSetbinaries元素下声明一个:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
  <id>Install-Package</id>
  <formats>
    <format>dir</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <moduleSets>
    <moduleSet>
      <binaries>
        <unpack>false</unpack>
        <dependencySets>
          <dependencySet>
            <unpack>false</unpack>
            <scope>runtime</scope>
            <outputDirectory>dependencies</outputDirectory>
          </dependencySet>
        </dependencySets>
      </binaries>
    </moduleSet>
  </moduleSets>
</assembly>

I am trying to setup the assembly plugin for a large multi-module project. The goal right now is to just get all of my artifacts into a directory. Here is my descriptor:

    <assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>Install-Package</id>
<formats>
    <format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
    <dependencySet>
        <unpack>false</unpack>
        <scope>runtime</scope>
        <outputDirectory>dependencies</outputDirectory>
    </dependencySet>
</dependencySets>
<moduleSets>
    <moduleSet>
        <binaries>
            <unpack>false</unpack>
        </binaries>
    </moduleSet>
</moduleSets>

Currently, this copies all of my artifacts to the assembly directory. So far, so good. The problem is that the dependencies folder only includes dependencies that are listed in the main pom file. Is there a way to include the dependencies of the sub modules in the assembly without listing them all in the root pom? (Including them all on the root pom would add extra unused dependencies to the sub modules if they are built separately).

Thanks!

解决方案

The problem is that the dependencies folder only includes dependencies that are listed in the main pom file.

Yes, this is what a "top" dependencySets does.

Is there a way to include the dependencies of the sub modules in the assembly without listing them all in the root pom?

Remove the "top" dependencySets and declare one under the binaries element of your moduleSet:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
  <id>Install-Package</id>
  <formats>
    <format>dir</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <moduleSets>
    <moduleSet>
      <binaries>
        <unpack>false</unpack>
        <dependencySets>
          <dependencySet>
            <unpack>false</unpack>
            <scope>runtime</scope>
            <outputDirectory>dependencies</outputDirectory>
          </dependencySet>
        </dependencySets>
      </binaries>
    </moduleSet>
  </moduleSets>
</assembly>

这篇关于Maven组件插件-包括子模块的依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆