Maven配置文件不会在子模块中继承

时间:2014-09-27 20:52:29

标签: java maven inheritance automated-tests profiles

我正在尝试使用maven配置文件分隔不同类型的测试(单元,集成,验收)。这是主pom文件的一部分:

        <properties>
            <build.profile.id>dev</build.profile.id>

            <skip.unit.tests>false</skip.unit.tests>
            <skip.integration.tests>true</skip.integration.tests>
            <skip.acceptance.tests>true</skip.acceptance.tests>
        </properties>

        <profiles>
            <profile>
                <id>dev</id>
            </profile>
            <profile>
                <id>integration-test</id>
                <properties>
                    <build.profile.id>integration-test</build.profile.id>
                    <skip.unit.tests>true</skip.unit.tests>
                    <skip.integration.tests>false</skip.integration.tests>
                    <skip.acceptance.tests>true</skip.acceptance.tests>
                </properties>
            </profile>
            <profile>
                <id>acceptance-test</id>
                <properties>
                    <build.profile.id>acceptance-test</build.profile.id>
                    <skip.unit.tests>true</skip.unit.tests>
                    <skip.integration.tests>true</skip.integration.tests>
                    <skip.acceptance.tests>false</skip.acceptance.tests>
                </properties>
            </profile>
        </profiles>
        <build>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.17</version>
                <configuration>
                    <skipTests>${skip.unit.tests}</skipTests>
                    <includes>
                        <include>**/*UnitTests.java</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.17</version>
                <executions>
                    <execution>
                        <id>integration-tests</id>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                        <configuration>
                            <skipTests>${skip.integration.tests}</skipTests>
                            <includes>
                                <include>**/*IntegrationTests.java</include>
                            </includes>
                        </configuration>
                    </execution>
                    <execution>
                        <id>acceptance-tests</id>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                        <configuration>
                            <skipTests>${skip.acceptance.tests}</skipTests>
                            <includes>
                                <include>**/*AcceptanceTests.java</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

如您所见,我正在使用配置文件信息根据使用的配置文件运行某些类型的测试。默认配置文件是dev,它只运行单元测试。它们可以像这样执行:

mvn clean test

对于集成和验收测试,我使用的是failafe插件:运行整合测试的示例如下:

mvn clean verify -P integration-test

当我从主pom模块运行它时,这工作正常,但从子模块运行它时它不起作用。测试被忽略了。查看子模块的有效pom我看不到配置文件。我做错了什么,或者这是maven的预期行为?如果无法通过这种方式实现配置文件继承(需要级联到层次结构中最深层的模块),那该怎么办呢?

更新:这是项目层次结构 项目目录

--main module
--commons module
--administration
----domain 
----data
----business
----web

1 个答案:

答案 0 :(得分:3)

对于multimodule项目,通常不直接执行模块。相反,您应始终执行主模块,但仅指定所需的子模块via -pl parameter。与直接运行模块有关的问题很多。


只是仔细检查了我参与的一些多模块项目,我们正在使用<pluginManagement>将父POM的插件配置传播到子项目。