pom config inheritance - maven surefire plugin

问题: I have a java project the has 3 "levels" in it. The pom in my top maven directory is looks like this: <groupId>com.my_app</groupId> <artifactId>my_app&l...

问题:

I have a java project the has 3 "levels" in it. The pom in my top maven directory is looks like this:

<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 (second level) pom is:

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

and finally, (3rd level) the pom the of the project that actually has test classes in it:

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

My question is - does this structure of poms allow for configuration inheritance from the top to the bottom pom? I mean, if I have the parallel configuration in the first pom in the maven-sirefure-plugin - will it take affect in test classes under first_module and under my_project ?


回答1:

Use pluginManagement tag in the parent's pom. Basically, <pluginManagement/> defines the settings for plugins that will be inherited by modules in your build:

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

Then, in the children's pom:

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

You don't need to specify the version, since it's inherited from the parent with all the configuration.

  • 发表于 2019-01-15 01:37
  • 阅读 ( 286 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除