Maven的组装,避免在zip文件中的完整路径? [英] maven assembly, avoiding full path in zip file?

查看:76
本文介绍了Maven的组装,避免在zip文件中的完整路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多模块项目,其中包含2个模块(每个模块都有自己的pom.xml)和一个指向这些模块的父pom.xml.

I have a multi-module project which contains 2 modules (each with its own pom.xml) and a parent pom.xml pointing to those modules.

当我在父pom上运行"mvn clean package"时,每个项目最终在其自己的目标文件夹下都有一个zip文件.我想将一个包含每个模块zip文件的zip文件打包在zip文件的根文件夹下,但是这样做有一些问题.

When I run "mvn clean package" on the parent pom, each project ends up with a zip file under it's own target folder. I would like to package a zip file containing each module zip file under the zip file's root folder but I am having some issues doing so.

我已经在父pom.xml文件夹中创建了一个程序集文件:

I have created an assembly file in the parent pom.xml folder:

<!-- Release distribution -->
<assembly>
<id>release</id>
<formats>
    <format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>

<fileSets>
    <fileSet>
        <directory>${basedir}/projectA/target/</directory>
        <outputDirectory>/</outputDirectory>
        <includes>
            <include>*.tar.gz</include>
        </includes>
    </fileSet>
    <fileSet>
        <directory>${basedir}/projectB/target/</directory>
        <outputDirectory>/</outputDirectory>
        <includes>
            <include>*.tar.gz</include>
        </includes>
    </fileSet>
</fileSets>
</assembly>

尽管上述方法可行,但是如果我们开始向该项目中添加越来越多的模块,那么必须不断更新该程序集会很烦人.

While the above works, if we start adding more and more modules to this project, it gets very annoying to have to keep updating this assembly.

理想情况下,我希望它自动进入模块的每个目标文件夹并在其中获取一个zip文件.

Ideally I'd like for it to automatically just go into every target folder for a module and get a zip file in there.

这可以通过完成

...
<fileSet>
        <directory>${basedir}</directory>
        <outputDirectory>/</outputDirectory>
        <includes>
            <include>**/target/*.tar.gz</include>
        </includes>
    </fileSet>

但是这里的问题是zip文件将包含完整路径,因此该zip文件将具有projectA/target/xxxx.zip和projectB/target/xxxx.zip,而不是在根文件夹中包含zip文件.我不想要的东西.

however the issue here is the zip file will contain full paths, so rather than having zip files inside the root folder, the zip file will have projectA/target/xxxx.zip and projectB/target/xxxx.zip which is exactly what I do not want.

有什么方法可以在Maven中制作一个简单的程序集,这样我不必每次添加一个新模块时都更新它,而zip里面没有完整的路径吗?

Is there any way to make a simple assembly in maven so I don't have to update it everytime I add a new module and not have full paths inside the zip?

编辑1

看来这根本不可能.您会得到一个结构良好的zip文件,很难维护程序集,或者得到一个易于维护但烦人的zip文件. 在找到合适的解决方案之前,我将不予回答

It looks like this is simply not possible. Either you get a nicely structured zip file with a hard to maintain assembly or you get an easy to maintain but annoingly structured zip file. I'll leave this unanswered until I can find a proper solution

编辑2

再次寻找解决方案.关于下面发布的khmarbaise解决方案,它存在一些问题: -它依赖于依赖项的程序集,在我的情况下,我只想要一个程序集的程序集(这更像fileSets而不是dependencyset) -这取决于我手动指定要包含在装配中的项目的事实.我已经在父pom中获得了此信息,该信息指定应构建哪些模块,因此,如果我从父pom中删除一个模块以使其不再构建,则程序集应该已经知道这一点并跳过选择该项目(原因是文件集似乎工作得很好,除了程序集zip内糟糕,不可控制的路径之外).除了从运行程序集的pom中删除添加的模块之外,我不必手动弄乱我想要包含的模块.

Back at looking for a solution for this again. Regarding khmarbaise solution posted below there are a few issues with it: - It relies on assemblies of dependencies, in my case I just want an assembly of assemblies (Which are more like fileSets and not dependencyset) - The fact that it relies on me manually specifying which projects I want to have included in the assembly. I already have this information in the parent pom which specifies which modules should be built, so if I remove a module from the parent pom so that it is no longer built, the assembly should already know that and skip picking that project (Reason for which fileset seems to work so well except for the shitty, non-controllable path inside the assembly zip). I shouldnt have to manually mess with what modules I want included other than simply removing adding modules from the pom I am running the assembly from.

没有人真的遇到过类似的问题吗?

Has nobody really ever run into a similar problem?

推荐答案

首先,我建议创建一个dist-packaging模块,其中包含生成的包.此外,听起来您的汇编描述符用于创建包含其他zip文件的最终存档是错误的.

First i would suggest to create dist-packaging module which contains the resulting package. Furthermore it sounds like your assembly-descriptor for creating the final archive which contains the zip files of others is wrong.

  <id>proj1-assembly</id>
  <formats>
      <format>zip</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
      <dependencySet>
          <outputDirectory>/</outputDirectory>
          <useProjectArtifact>false</useProjectArtifact>
          <unpack>false</unpack>
          <scope>runtime</scope>
      </dependencySet>
  </dependencySets>

但是您必须意识到,您必须像通常的模块依赖项那样维护dist-module中的依赖项,如下所示:

But you must be aware that you have to maintain the dependencies in the dist-module as usual module dependencies like the following:

  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>package-one</artifactId>
      <version>${project.version}</version>
      <classifier>package-1-assembly</classifier>
      <type>zip</type>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>package-two</artifactId>
      <version>${project.version}</version>
      <classifier>package-2-assembly</classifier>
      <type>zip</type>
    </dependency>
    ....

在这里可以找到完整的示例.

这篇关于Maven的组装,避免在zip文件中的完整路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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