0

I'm trying to separate different kinds of tests (unit, integration, acceptance) by using maven profiles. This is the part of the main pom file:

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

As you can see I'm using the profile information to run certain types of tests based on the profile that is used. Default profile is dev and it will only run unit tests. They can be executed like this:

mvn clean test

For integration and acceptance tests I use failsafe plugin: Example of running integartion tests would be:

mvn clean verify -P integration-test

This works fine when I run it from the main pom module, but it doesn't work when running it from the child module. Tests are just ignored. Looking at the effective pom for child module I don't see the profiles. Am I doing something wrong or is this is expected behavior from maven? If profile inheritance (needs to cascade to deepest modules in the hierarchy) can't be achieved this way how can it be done?

Update: This is the project hierarchy project directory

--main module
--commons module
--administration
----domain 
----data
----business
----web
Rade Milovic
  • 965
  • 4
  • 13
  • 29
  • What is your POM hierarchy? Based on this - http://stackoverflow.com/questions/3695394/inheriting-maven-profiles - it should work. – Pavel Horal Sep 27 '14 at 21:35
  • I mean... your modules have the multi-module POM as their parent, right? – Pavel Horal Sep 27 '14 at 21:38
  • I've updated the question. Yes they have. – Rade Milovic Sep 27 '14 at 21:43
  • This article might be relevant - http://www.dashbay.com/2011/03/maven-profile-inheritance/ . It seems that although parent profiles are being activated, its the plugins which are not inherited. You should use `pluginManagement`. – Pavel Horal Sep 27 '14 at 21:56
  • 1
    From the official sources it seems that inheritance should work - http://maven.apache.org/guides/mini/guide-configuring-plugins.html#Using_the_inherited_Tag_In_Build_Plugins . So much for the contradicting information :). – Pavel Horal Sep 27 '14 at 22:00
  • I don't think that is the case. Effective pom shows that plugins are inherited. – Rade Milovic Sep 27 '14 at 22:17
  • The thing is that I wrongly named the test. Stupid of me. I will mark your answer as correct. There is a command for checking the profiles: mvn help:all-profiles. It shows that profiles are indeed inherited. Sorry for this. Message to myself: I should step away from the code and look at it tommorow again. – Rade Milovic Sep 27 '14 at 22:29
  • Nice... :)... was in the process of setting up my own test. – Pavel Horal Sep 27 '14 at 22:30
  • 1
    Re _"Looking at the effective pom for child module I don't see the profiles."_ I assume the aggregator project (the one declaring s) is not the one declared as in the (sub-)modules or in one of their pearents. Inheritance and Aggreqation don't have necessarily the same tree hierarchy, see [Project Inheritance vs Project Aggregation](https://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Project_Inheritance_vs_Project_Aggregation). – Gerold Broser Sep 27 '14 at 22:32
  • Sorry again. It would be nice if Stack Overflow had the option for sending the "forgive me" gift. – Rade Milovic Sep 27 '14 at 22:34

1 Answers1

3

With multimodule project you usually don't execute modules directly. Instead you should always execute the main module, but specify only your desired submodule via -pl parameter. There are a lot more issues connected with running modules directly.


Just double checked some multi-module projects I have participated on and I we are using <pluginManagement> to propagate plugin configuration form parent POM to child projects.

Pavel Horal
  • 17,782
  • 3
  • 65
  • 89
  • Thanks for the advice. As you said this is not really an issue because I can run the main module. I just wanted to see is this possible because it would be very handy to me. I will have multiple submodules which will also have their submodules. I want to put them in separate repositories so they can be developed independently. – Rade Milovic Sep 27 '14 at 21:36
  • It is possible to develope modules independently, but all modules they depend on, the parent included, must have already been deployed. Btw, are your submodules correctly declaring parents? – kaqqao Sep 27 '14 at 21:45