Maven:更改“测试"从本地.m2到目标的阶段目录? [英] Maven: Change the "test" phase directory from local .m2 to target?

查看:152
本文介绍了Maven:更改“测试"从本地.m2到目标的阶段目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果需要补救,请原谅我,但我仍然不熟悉Maven及其功能.

Forgive me if this is remedial, but I am still new to Maven and it's functionality.

在我的项目中,当它构建"并进入编译阶段时,它将创建一个仅包含已编译库的目标目录,并更新(或创建).m2本地目录.

In my project, when it "builds" and gets to the compile phase, it will create a target directory with just compiled libraries and update (or create if not there) the local .m2 directory.

进入测试"阶段时,我希望它是根据目标目录的库文件而不是本地.m2目录构建的.

When I get to the "test" phase, I want it to build against the target directory's library files, and not the local .m2 directory.

任何提示,推荐或建议将不胜感激.谢谢!

Any hints, recommendations, or suggests would be greatly appreciated. Thanks!

推荐答案

Maven拥有反应堆"的概念,这只是正在构建的项目列表的一个幻想术语.在Maven构建的开始和结束时,Maven打印出此项目列表(如果定义,则使用/project/name,否则使用groupId:artifactId).

Maven has this concept of "the reactor", which is just a fancy term for the list of projects being built. At the start of a Maven build, and at the end, Maven prints out this list of projects (using /project/name if defined or groupId:artifactId otherwise).

对于反应堆中的每个项目,Maven都会维护一个已附加工件的列表.默认情况下,将附加每个模块的pom.xml,并且在每个插件运行时,它们可以选择附加其他工件.大多数插件不附带工件,以下是一些插件:

For each project in the reactor, Maven maintains a list of artifacts that have been attached. By default, each module's pom.xml is attached, and as each plugin runs, they have the option of attaching additional artifacts. Most plugins do not attach artifacts, here are some plugins that do:

  • jar:jar创建一个.jar并将其附加
  • war:war创建一个.war并将其附加
  • source:jar创建源Java代码的.jar,并将其附加到source
  • 的分类器上
  • java doc:jar创建JavaDocs广告的.jar,并为其附加javadoc
  • 分类器
  • jar:jar creates a .jar and attaches it
  • war:war creates a .war and attaches it
  • source:jar creates a .jar of the source Java code and attaches it with a classifier of source
  • java doc:jar creates a .jar of the JavaDocs ad attaches it with a classifier of javadoc

还有一个默认的主工件(这是被jar:jar取代的工件),它实际上是目录而不是文件,因此不会被安装或部署到本地存储库高速缓存或远程数据库存储库.

There is also a default primary artifact (this is the one that gets replaced by jar:jar) which is actually a directory and not a file, as such it will not get installed or deployed to the local repository cache or a remote repository.

因此,当在反应堆中且尚未连接主工件的插件尚未运行,而另一个插件请求主工件时,它将获得目录${project.build.outputDirectory}.如果在附加了主要工件之后,将提供该主要工件.

So when in the reactor, and a plugin that attaches the primary artifact has not run yet, and another plugin asks for the primary artifact, it will be given the directory ${project.build.outputDirectory}. If after the primary artifact as been attached, then that primary artifact will be provided.

test阶段发生在package阶段之前,因此将使用目录而不是.jar. integation-test阶段发生在此之后,因此将始终使用.jar.

The test phase happens before the package phase, so will use the directory and not the .jar. The integation-test phase happens after, so will always use the .jar.

在多模块项目中,事情变得更加复杂(这是我的长篇介绍会为您提供帮助的地方)

Things get more complex in a multi-module project (which is where my long intro should help you out)

Maven必须构建测试类路径.如果依赖项之一在反应堆内,则Maven将使用附加到反应堆的工件.否则,它将使用本地缓存(必要时从远程存储库填充).

Maven has to build the test classpath. If one of the dependencies is within the reactor, Maven will use the artifact attached to the reactor. Otherwise it will use the local cache (populating from the remote repositories if necessary).

跑步时

mvn test

在从根到多层的项目中,不会替换默认的(基于目录的)工件,因此模块内的类路径将到达target/classes目录.

In a multimdule project from the root, there is no replacement of the default (directory-based) artifact, so intra-module classpath will be to the target/classes directories.

跑步时

mvn package 

但是,在同一个项目中,由于每个模块都按顺序完成其生命周期,因此所有从属模块都将在其.jar文件中交换为附加的工件.

In the same project, however, because each module completes its life cycle sequentially, all the dependent modules will have swapped in their .jar files as their attached artifact.

所有这些都应该向您表明Maven正在做明智的事情.希望对您有所帮助.

All of this should show you that Maven is doing the sensible thing. Hope this has helped.

这篇关于Maven:更改“测试"从本地.m2到目标的阶段目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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