I'm working on a Maven project which uses both the Surefire and Failsafe plugins in the same module. The configurations for both plugins are pretty much identical, except for one element (classpathDependencyExcludes
), as you can see.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<skipTests>${skipTests}</skipTests>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<argLine>-javaagent:"${project.build.directory}/openejb-javaagent-${tomee.version}.jar"</argLine>
<workingDirectory>${project.build.directory}</workingDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<skipTests>${skipTests}</skipTests>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<argLine>-javaagent:"${project.build.directory}/openejb-javaagent-${tomee.version}.jar"</argLine>
<workingDirectory>${project.build.directory}</workingDirectory>
<classpathDependencyExcludes>
<classpathDependencyExclude>javax:javaee-api</classpathDependencyExclude>
</classpathDependencyExcludes>
</configuration>
</plugin>
I was wondering if there was a way to share the common section of the configuration between the two plugins by writing it down once instead of multiple times. If not, in the hypothesis that both configurations were identical, would it be possible?
First of all, you don't need to set all the properties explicitly. skipTests
has already the value of ${skipTests}
, no need to repeat that. forkCount
has already the default value 1.
Some of the other properties can be set in the <properties>
section, like reuseForks
and argLine
.
Then there is very little left to worry about.