Maven多模块项目-复制所有“包" JARS从子模块到父/目标/ [英] Maven multi-module project - copying all "package" JARS from submodules into parent/target/

查看:134
本文介绍了Maven多模块项目-复制所有“包" JARS从子模块到父/目标/的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有很多子模块的Maven项目.我正在寻找一种获取由聚集的POM的/target/目录中包含的子模块生成的所有.jar文件的方法,因此以后可以方便地使用它们.

I have a maven project with quite a few submodules. What I am looking for is a way to get all the .jar files produced by the sub-modules included in the aggregating POM's /target/ directory, so they can be conveniently used afterwards.

  • 它们不需要合并.最好不要,但是如果必须 那就可以了.
  • 不在乎依赖性
  • 这主要是为了方便起见
  • They don't need to be merged. Preferably not, but if they must be then that is ok.
  • Don't care about dependancies
  • This is primarily for convenience, at this point

我正在做的工作的基本版本:

A basic version of what I am looking at doing:

Prj1/pom.xml  =>  prj1/target/proj1.jar  (and classes/generated-sources/etc)
Prj2/pom.xml  =>  prj2/target/proj2.jar
Main/pom.xml  =>
                  main/target/proj1.jar
                  main/target/proj2.jar
                  ... classes/generated-sources not needed at all,
                  ... but they could be combined here.  I assume they will be

我一直在阅读,并且也使用了SO的一些建议.到目前为止,我还没有找到执行此操作的方法,但是我敢肯定它已经存在.

I've been reading, and using some suggestions from SO as well. So far I haven't found a way to do this, but I'm sure it is there.

对于所有附带的子项目,我已经放弃了以简单的方式使其工作的想法.到目前为止,我最好的答案是使用依赖性插件手动(再次)指定要包括的每个子模块.这个想法是为了能够轻松地为数十个客户端配置POM,只需简单地包含必要的模块,然后将其神奇地将所有子模块的jar放在一个位置即可.当您不做很多事情时,Maven非常不错,但是尝试使用尖括号税是难以置信的.

I've given up on getting this to work in a simple way, for all included subprojets. The best answer I have so far is using the dependancy plugin to manually specify (again), each and every sub-module to be included. The idea was to be able to configure the POMs easily for the dozens of clients, simply including the modules necessary and then having it magically stick all the sub-modules's jars in one location. Maven is pretty nice, when you don't do much with it, but the angle bracket tax is incredible when you try.

我仍然感到奇怪的是,这样的标准制定任务(根据SO提出的问题以及任何正常项目会做什么)是如此困难. maven3更好吗?

I still find it odd that such standard-seeming tasks (judging from the questions asked on SO, and what any normal project would do) are so difficult. Is maven3 better?

推荐答案

您可以尝试 maven-dependency-插件:复制插件:目标.

You could try the maven-dependency-plugin:copy plugin:goal.

您必须将其添加到要复制的所有子模块的pom中. 或只是在父pom中(请参阅评论).

You will have to add this to the pom of all submodules that you want to copy. Or just in the parent pom (see comments).

    <build>
        <plugins>
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-dependency-plugin</artifactId>
              <executions>
                <execution>             
                  <id>copy-artifact</id>
                  <phase>package</phase>
                  <goals>
                    <goal>copy</goal>
                  </goals>
                  <configuration>
                    <artifactItems>
                        <artifactItem>
                          <groupId>${project.groupId}</groupId>
                          <artifactId>${project.artifactId}</artifactId>
                          <version>${project.version}</version>
                          <type>${project.packaging}</type>
                        </artifactItem>
                    </artifactItems>
                    <outputDirectory>../Main/target/dependencies</outputDirectory>
                  </configuration>
                </execution>
              </executions>
            </plugin>
        </plugins>
    </build>

如果确实将其放在父pom中,请记住,只有当您的整个项目只有一个模块深时,它才能很好地工作.这意味着,如果父模块下的模块具有自己的子模块,则它们不会以所需的文件夹结尾.您的文件夹结构将如下所示:

If you do put this in the parent pom, keep in mind that it will work nicely only if your whole project is one module deep. Meaning that if the the modules under the parent module have their own submodules, they will not end up in the desired folder. Your folder structure will look like this:

- Parent
  - Module 1
    - Sub module 1
    **Main**
  - Module 2
  **Main**

为避免这种情况,请使用上述配置创建一个专用模块,然后手动指定要复制的每个模块.这样,所有模块,无论模块有多深,都将保存在一个文件夹中.

To prevent this, create a dedicated module with above configuration, and specify manually each module that you want to copy. This way all modules, no matter how deep they are will end up in one folder.

这篇关于Maven多模块项目-复制所有“包" JARS从子模块到父/目标/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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