Disable unit tests in a submodule using system property

In my scenario I want to disable running unit tests for some modules during multi-module build, e.g.

mvn -Dmaven.test.skip.module1=true -Dmaven.test.skip.module2=true install

In module1 I can define a profile:

<profile>
    <id>disable-unit-tests</id>

    <activation>
        <property>
            <name>maven.test.skip.module1</name>
            <value>true</value>
        </property>
    </activation>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <skipTests>true</skipTests>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</profile>

but when I try to generalize it and put to parent POM:

<profile>
    <id>disable-unit-tests</id>

    <activation>
        <property>
            <name>maven.test.skip.${project.artifactId}</name>
            <value>true</value>
        </property>
    </activation>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <skipTests>true</skipTests>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</profile>

it is not activated with above mentioned command.

What I am doing wrong? Is there any solution?

Answers


Profile activation via properties cannot depend on properties, because properties are resolved later in the building of the default model.

In your case, the profile would be actived if the property 'maven.test.skip.${project.artifactId}' would be set.

Take a look at the following description: http://maven.apache.org/ref/3.1.1/maven-model-builder/

You need either to explicitly define your profile in all your submodules or use another plugin (either a self made) or gmaven/antrun to set a property depending on the presence of another one.

Update

Example for the gmaven solution:

<build>
  <plugins>
    <plugin>
      <groupId>org.codehaus.gmaven</groupId>
      <artifactId>groovy-maven-plugin</artifactId>
      <version>2.0</version>
      <dependencies>
        <dependency>
          <groupId>org.codehaus.groovy</groupId>
          <artifactId>groovy-all</artifactId>
          <version>2.1.8</version>
        </dependency>
      </dependencies>
      <executions>
        <execution>
          <id>createSkipProperty</id>
          <phase>initialize</phase>
          <goals>
            <goal>execute</goal>
          </goals>
          <configuration>
            <source>
              if (properties["maven.test.skip.${project.artifactId}"])
                project.properties.setProperty("skip.this.module", "true")
            </source>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
  <pluginManagement>
    <plugins>
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skipTests>${skip.this.module}</skipTests>
        </configuration>
      </plugin>
    </plugins>
  </pluginManagement>
</build>

This sets a skip.this.module property on the presence of maven.test.skip.${project.artifactId}. Advantage of this solution is, that you only need to define it once in your parent.


Need Your Help

What does C "Sleep" function (capital "S") do on a Mac?

xcode macos sleep

Note the capital "S" in Sleep. Sleep with a capital "S" is a standard function that sleeps milliseconds on the PC. On Mac OS X, there is no such symbol. However, the Xcode linking environment se...

AngularJS directives attributes access from the controller

javascript events controller angularjs angularjs-directive

I am trying to access the attributes of a directive in the controller function. However, by the time I access it, it is undefined. I noticed that if I do a simple timer it works. Is there a way to