如何在多模块Maven项目中使用Maven组件插件 [英] How to use Maven assembly plugin with multi module maven project

查看:98
本文介绍了如何在多模块Maven项目中使用Maven组件插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Maven的新手,并且花了大约3天的时间使用使用Maven程序集插件管理多模块依赖项

I am new to maven and spent ~3 days in generating the zip file with assembly plugin refering to http://www.petrikainulainen.net/programming/tips-and-tricks/creating-a-runnable-binary-distribution-with-maven-assembly-plugin/ My project is multi module, so I also referred to Managing multi-module dependencies with Maven assembly plugin

我仍然有几个效率低下的地方.下面是assembly.xml(我从第一个链接继承)

Still I have several inefficiencies. Below is assembly.xml (which I inherited from 1st link)

 <assembly>
<id>bin</id>
<!-- Generates a zip package containing the needed files -->
<formats>
    <format>zip</format>
</formats>

<!-- Adds dependencies to zip package under lib directory -->
<dependencySets>
    <dependencySet>
        <!-- Project artifact is not copied under library directory since it is 
            added to the root directory of the zip package. -->
        <useProjectArtifact>false</useProjectArtifact>
        <outputDirectory>lib</outputDirectory>
        <unpack>false</unpack>

    </dependencySet>
</dependencySets>
<moduleSets>
    <moduleSet>

        <!-- Enable access to all projects in the current multimodule build! <useAllReactorProjects>true</useAllReactorProjects> -->

        <!-- Now, select which projects to include in this module-set. -->
        <includes>
            <include>com.XX:YY-main</include>
        </includes>

        <!--<binaries> <outputDirectory>YY-main/target</outputDirectory> <unpack>false</unpack> 
            </binaries> -->
    </moduleSet>
</moduleSets>
<fileSets>
    <!-- Adds startup scripts to the root directory of zip package. The startup 
        scripts are located to src/main/scripts directory as stated by Maven conventions. -->
    <fileSet>
        <directory>${project.build.scriptSourceDirectory}</directory>
        <outputDirectory>conf</outputDirectory>
        <includes>
            <include>*</include>
        </includes>
    </fileSet>
    <fileSet>
        <directory>${project.build.directory}</directory>
        <outputDirectory></outputDirectory>
        <includes>
            <include>log4j.properties</include>
        </includes>
    </fileSet>
    <!-- adds jar package to the root directory of zip package -->
    <fileSet>
        <directory>${project.build.directory}</directory>
        <outputDirectory></outputDirectory>
        <includes>
            <include>*with-dependencies.jar</include>
        </includes>
    </fileSet>
</fileSets>

下面是pom.xml(主要或主要)

Below is the pom.xml (primary or main)

 <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
             <configuration>                    <descriptors>
              <descriptor>YY-main/src/main/assembly/assembly.xml</descriptor>   
         <!-- <descriptor>DummyAssembly.xml</descriptor> -->

                </descriptors>
            </configuration>
        </plugin>   

问题:

1)由于在主pom中引用了assembly.xml,因此所有子模块也都被压缩了.如何仅指定要压缩的某些子模块,而其他所有模块都将被忽略.我试图将YY-main/src/main/assembly/assembly.xml从主pom移到子/子模块pom,并且在main中有dummyassembly.xml却什么也没做.但这是行不通的(可能是因为dummyassembly.xml缺少某些必需的行).尝试了几件事,但似乎无济于事

1)Since assembly.xml is referred in primary pom, all submodules also get zipped. How can I specify only certain submodules to be zipped, while all others get ignored. I tried to move YY-main/src/main/assembly/assembly.xml from main pom to child/submodule pom and have dummyassembly.xml in main which does nothing. But that is not working (possibly because dummyassembly.xml is missing some required lines). tried few things, but nothing seem to work

2)同样在assembly.xml(依赖集)中,它将所有库都复制到"lib"文件夹中.我如何避免这种情况.再次基于 http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#class_dependencySet ,但无济于事.

2)Also in assembly.xml (dependencyset), it is copying all the libraries to "lib" folder. How can I avoid this. again I tried few things (exclusion..) based on http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#class_dependencySet but nothing worked.

有人可以为我提供一些具体的陈述,我应该在pom或汇编文件中进行更改以解决1和2的感谢

Can some one provide me with specific statements that I should change in my pom or assembly files to address 1 and 2-thanks

推荐答案

您应该更改的基本操作是创建一个单独的模块,在其中进行如下所示的包装.

The basic thing you should change is to create a separate module where you do the packaging which will look like this.

   +-- root (pom.xml)
        +--- mod-1 (pom.xml)
        +--- mod-2 (pom.xml)
        +--- mod-assembly (pom.xml)

mod-assembly中的pom看起来像这样:

The pom in the mod-assembly will look like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.test.parent</groupId>
    <artifactId>root</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </parent>

  <artifactId>dist</artifactId>
  <packaging>pom</packaging>

  <name>Packaging Test : Distribution</name>

  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>module-one</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>module-two</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <id>make-bundles</id>
            <goals>
              <goal>single</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <descriptors>
                <descriptor>proj1-assembly.xml</descriptor>
              </descriptors>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

这将解决在每个孩子中运行maven-assembly-plugin的问题以及虚拟描述符的问题. 在这里您可以找到这种结构的真实示例.

That will solve the problem with running maven-assembly-plugin in every child and the problem with the dummy descriptor. Here you can find a real example of such structure.

此外,在一个文件夹中包含模块,在另一个文件夹中包含依赖项,您可以使用

Furthermore having the modules in one folder and the dependencies in an other folder you can use a assembly descriptor like this:

  <id>bin</id>
  <formats>
    <format>zip</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <dependencySet>
          <useProjectArtifact>false</useProjectArtifact>
          <useTransitiveDependencies>true</useTransitiveDependencies>
          <outputDirectory>lib</outputDirectory>
          <unpack>false</unpack>
          <excludes>
            <exclude>${project.groupId}:*:*</exclude>
          </excludes>
      </dependencySet>
  </dependencySets>
  <moduleSets>
    <moduleSet>
      <useAllReactorProjects>true</useAllReactorProjects>
      <binaries>
        <outputDirectory>modules</outputDirectory>
        <unpack>false</unpack>
      </binaries>
    </moduleSet>
  </moduleSets>

这篇关于如何在多模块Maven项目中使用Maven组件插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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