我有一个 java 项目,其中有 3 个“级别”。 我的顶级 maven 目录中的 pom 如下所示:
<groupId>com.my_app</groupId>
<artifactId>my_app</artifactId>
<version>LATEST-SNAPSHOT</version>
<modules>
<module>first_module</module>
<module>second_module</module>
</modules>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<parallel>classes</parallel>
<threadCount>10</threadCount>
</configuration>
</plugin>
</plugins>
first_module(第二级)pom 是:
<parent>
<groupId>com.my_app</groupId>
<artifactId>my_app</artifactId>
<version>LATEST-SNAPSHOT</version>
</parent>
<groupId>com.my_app.first_module</groupId>
<artifactId>first_module</artifactId>
<version>LATEST-SNAPSHOT</version>
...
<plugins>
<plugin>
<version>2.22.1</version>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
最后,(第三级)项目中实际包含测试类的 pom:
<parent>
<artifactId>first_module</artifactId>
<groupId>com.my_app.first_module</groupId>
<version>LATEST-SNAPSHOT</version>
</parent>
<artifactId>my_project</artifactId>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
</plugins>
我的问题是 - 这种 pom 结构是否允许从顶部到底部 pom 的配置继承?我的意思是,如果我在 maven-sirefure-plugin 的第一个 pom 中有 parallel 配置 - 它会在 first_module 下的测试类中生效吗> 并在 my_project 下?
最佳答案
使用 pluginManagement
父级 pom 中的标记。基本上,<pluginManagement/>
定义将由构建中的模块继承的插件的设置:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<parallel>classes</parallel>
<threadCount>10</threadCount>
</configuration>
</plugin>
</plugins>
</pluginManagement>
然后,在 children 的 pom 中:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
您不需要指定版本,因为它是从父级继承的所有配置。
关于java - pom配置继承-maven Surefire插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54167748/