唯一能控制
目标
处决
)在Maven构建期间执行,无论您的项目是否具有模块,都是通过概要文件执行的。
例如:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>module1</module>
<module>module2</module>
</modules>
</project>
/模块1/pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.company</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>module1</artifactId>
</project>
/模块2/pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.company</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>module2</artifactId>
<profiles>
<profile>
<id>module2:ignore-compile</id>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
mvn -Pmodule2:ignore-compile package
. 您将注意到源代码编译(但仅限于此目标/执行!)将忽略模块2。
你也可以使用
activation
<profiles>
<profile>
<id>module2:ignore-compile</id>
<activation>
<property>
<name>module2:ignore-compile</name>
</property>
</activation>
....
</profile>
</profiles>
然后使用命令:
mvn -Dmodule2:ignore-compile package
/pom.xml文件
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>module1</module>
</modules>
<profiles>
<profile>
<id>with:module2</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>module2</module>
</modules>
</profile>
</profiles>
</project>
忽略
module2
mvn '-P!with:module2' package