我定义了一个 Maven 多模块构建,其中一个模块仅用于生成源。它不会编译、测试或打包,并且除了生成源文件之外不会创建任何 Artifact 。
我还没有找到一种方法,可以只在生成器模块上执行 generate-sources
之前的阶段,无论我在启动多模块构建时指定的阶段如何。有一些解决方案可以跳过不需要的阶段,但这不是一个真正的选择,因为其中只有很多。
对于那些想知道为什么我想要它的人:构建使用 tycho 和 fornax oaw 插件,因此我必须将构建拆分为两个单独的 pom 文件,并使用多模块构建文件来“一起”执行它们。
最佳答案
看到您的 latest question 后我想我可能会给你一个解决方案。
我猜你所有的../projectN/generate/pom.xml
都将顶级pom作为其父级,但我建议你创建一个特殊的generate-parent
pom 具有特殊的插件管理功能,可以为您跳过所有阶段。
在顶层创建一个名为 generate-parent
的额外文件夹:
<modules>
<module>../generate-parent/pom.xml</module> <!-- NEW FOLDER WITH POM -->
<module>../project1/generate/pom.xml</module>
<module>../project1/pom.xml</module>
<module>../project2/generate/pom.xml</module>
<module>../project2/pom.xml</module>
<!-- and many more projects with or without generate sub modules -->
</modules>
这个新的 pom 将像往常一样继承自父 pom,但仅添加一些额外的插件管理:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>your-group</groupId>
<artifactId>your-parent-pom-artifact-id</artifactId>
<version>your-parent-version</version>
</parent>
<artifactId>generate-parent</artifactId>
<packaging>pom</packaging>
<name>${project.artifactId}-${project.version}</name>
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<id>default-resources</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testResources</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<executions>
<execution>
<id>default-test</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-jar</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-install</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
现在有了这个 pom,所有默认阶段都被禁用。
现在在所有生成项目中使用此 pom。上面的 pom 继承了父 pom 中的所有好东西,但只是添加了这些特殊的插件管理部分,这些部分禁用了 generate-sources
之后的阶段。
project1/generate/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>your-group</groupId>
<artifactId>generate-parent</artifactId>
<version>your-parent-version</version>
<relativePath>../../generate-parent</relativePath>
</parent>
...
The rest of your pom
...
</project>
这将有效地完成您想要的操作,generate-parent
是中间人,它为这些生成项目添加您想要的所有插件管理。
关于java - Maven 多模块构建中的生命周期阶段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12928465/