Reputation: 417
I would like maven to run test phase only if a parameter is defined. For example:
mvn test -Dserver=hosname
If server was not specified (or empty) - I don't want the test to run (not in mvn test, nor in mvn install).
How do I do that? How do I get the value of the parameter (e.g. "server") inside my code?
Upvotes: 0
Views: 230
Reputation: 1717
Profile can do that in maven what u want
for ex:
<profiles>
<profile>
<id>server</id>
<activation>
<property>
<name>server</name>
<value>${hosname}</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
Upvotes: 1
Reputation: 97507
The profile can be used like this:
<profiles>
<profile>
<activation>
<property>
<name>server</name>
</property>
</activation>
<!-- do whatever you need to do -->
</profile>
</profiles>
Upvotes: 0
Reputation:
Assuming you are using junit:
Assume
to check the property (see @BeforeClass
below) and skip the test if the property is null.
public class RunIfServerProperty {
@BeforeClass
public static void oneTimeSetup() {
Assume.assumeNotNull(System.getProperty("server"));
}
}
see also Assume
javadoc
Upvotes: 2