繁体   English   中英

pom 配置继承 - maven surefire 插件

[英]pom config inheritance - maven surefire plugin

我有一个 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>

最后,(第 3 级)项目中实际包含测试类的 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 中有并行配置 - 它会影响first_modulemy_project下的测试类吗?

在父级的 pom 中使用pluginManagement标签。 基本上, <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>

然后,在孩子们的 pom 中:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM