【发布时间】:2017-07-09 09:27:06
【问题描述】:
我正在使用 maven 多模块构建,如下所示
<modules>
<module>module1</module>
<module>module2</module>// dependant on module 1
<module>module3</module>// dependant on module 2
<module>warApplication</module>// its a war file dependant on above modules
</modules>
目前的构建行为:- 如果我只在模块 1 中进行更改,maven 将构建模块 2、模块 3 源文件,然后将模块 1、模块 2、模块 3 jar 文件放在 warApplication/target/lib 下。
当我触发构建时是否有配置/方式,maven 验证模块下是否有任何文件被修改,如果没有跳过该模块。对于战争文件,它将把具体的 被修改的lib文件。这将节省大量时间。
要检查模块下是否有任何文件被修改,maven 可以存储上次构建时间。在开始构建之前,它会检查在最后一个构建时间戳之后是否有任何文件被修改,如果是,则构建它,否则跳过它。
是否有任何可用的 maven 插件?
更新:-
我的项目结构是
TopFolder
.mvn directory -> extensions.xml
build directory->build-Projects-> pom.xml
build directory-> parent -> pom.xml
modules - > module1 -> pom.xml
modules - > module2 -> pom.xml
modules - > module3 -> pom.xml
这是我在父 pom 中包含模块
<modules>
<module>../../modules/module1</module>
<module>../../modules/module2</module>
</modules>
。我在以下两个项目中都包含了 scm 标签<developerConnection>scm:svn:https://comp.com/svn/trunk</developerConnection>
build directory->build-Projects-> pom.xml
build directory-> parent -> pom.xml
从build directory->build-Projects-> pom.xml 运行构建。
但问题是当我更改任何文件任何模块并从build directory-> pom.xml 运行构建时,它没有检测到模块更改?
【问题讨论】:
-
我知道,这不是答案,但试试 gradle。至少它会跳过未触及模块的重建。
-
您应该考虑到即使您没有接触过模块 2,构建的结果也可能会有所不同。首先,模块 2 的构建可能会中断,因为您更改了模块 1 中由模块 2 调用的某个类。出于同样的原因,模块 2 的测试可能会通过或中断,具体取决于模块 1。此外,还有更罕见的问题就像在模块 2 中使用模块 1 的公共常量。这些被编译到模块 2 中,因此即使您只更改模块 1 中的常量,模块 2 的字节码也可以更改。
-
@JFMeier 你是对的。在这种情况下,我还需要构建模块 2。但是拉特说我确信没有像这样的改变会破坏模块 2,有没有办法我可以跳过模块 2 的构建
-
您可以简单地使用:根文件夹中的
mvn -pl module1, warApplication(手动)(在使用之前,您需要安装 mvn)。不需要配置文件。或者你可以看看incremental-module-build -
@khmarbaise 在您的评论中每个问题都有一个问题 1. 我的 pom.xml 有
<modelVersion>4.0.0</modelVersion>groupId>com.myCompany</groupId> <artifactId>customer</artifactId><packaging>jar</packaging> <name>customer</name><version>1.15</version>然后我尝试了 mvn -pl customer ,我得到了错误org.apache.maven.MavenExecutionException: Could not find the selected project the reactor: customer。