Java pom配置继承-maven surefire插件

Java pom配置继承-maven surefire插件,java,junit,pom.xml,maven-surefire-plugin,parent-pom,Java,Junit,Pom.xml,Maven Surefire Plugin,Parent Pom,我有一个java项目,其中有3个“级别”。 我的顶级maven目录中的pom如下所示: <groupId>com.my_app</groupId> <artifactId>my_app</artifactId> <version>LATEST-SNAPSHOT</version> <modules> <module>first_module</module> <mo

我有一个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>
com.my\u应用程序
我的应用程序
最新快照
第一单元
第二单元
...
org.apache.maven.plugins
maven surefire插件
2.22.1
班级
10
第一个模块(第二级)pom是:


com.my_应用程序
我的应用程序
最新快照
com.my_app.first_模块
第一单元
最新快照
...
2.22.1
org.apache.maven.plugins
maven surefire插件
最后,(3rd level)实际包含测试类的项目的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>

第一单元
com.my_app.first_模块
最新快照
我的计划
...
org.apache.maven.plugins
maven surefire插件
2.22.1
我的问题是-pom的这种结构是否允许从顶部到底部pom的配置继承?我的意思是,如果我在maven sirefure插件的第一个pom中有并行配置,它会在第一个\u模块我的\u项目下的测试类中生效吗?

在父级pom中使用标记。基本上,
定义将由构建中的模块继承的插件的设置:

<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>

org.apache.maven.plugins
maven surefire插件
2.22.1
班级
10
然后,在儿童pom中:

<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
    </plugin>
</plugins>

org.apache.maven.plugins
maven surefire插件

您不需要指定版本,因为所有配置都是从父级继承的。

非常感谢!如果我想拥有特定于项目的配置,我可以将其添加到子pom中?它将同时包含来自父级和子级的配置?@OfekAgmon是的,您可以覆盖子级插件中的配置。但例如,假设我在父级pom中有并行配置(类),我可以在子级pom中添加另一个不同的配置,它们都可以工作吗?或者,一旦我在子pom中有了配置标记,它就会覆盖父项的整个配置?它将首先应用父项,然后应用子项配置,因此它不会覆盖父项的整个配置。
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
    </plugin>
</plugins>