I need to change the classpath value used by maven-compiler-plugin to compile tests and i can't find any way to do it...
I've read :
- maven add a local classes directory to module's classpath
- Maven: add a folder or jar file into current classpath
But these solutions are not good for me.
More precisely, we're building client jar to use this API and we need to build this client twice :
- One with source & target to 1.8 for new client
- One with source & target to 1.7 for client still using JDK7
Here's the configuration of the maven-compiler-plugin into the pluginManagement of my parent POM :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<includes>
<include>**/*.java</include>
</includes>
<target>1.8</target>
<source>1.8</source>
<fork>true</fork>
<encoding>UTF-8</encoding>
</configuration>
<executions>
<execution>
<id>jdk7</id>
<phase>none</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>1.7</source>
<target>1.7</target>
<fork>true</fork>
<outputDirectory>${project.build.directory}/classes/jdk7/</outputDirectory>
</configuration>
</execution>
<execution>
<id>jdk8</id>
<phase>none</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<fork>true</fork>
<outputDirectory>${project.build.directory}/classes/jdk8/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
The phase is set to "none" to disable these executions by default and they are executed only for the client.
This is the configuration of my client POM :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>jdk7</id>
<phase>compile</phase>
</execution>
<execution>
<id>jdk8</id>
<phase>compile</phase>
</execution>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
As you can see, i've disabled the execution "default-compile", because it's compiling a 3rd times the source directly in the target/classes folder and it's quite dirty in my case. I only want JDK7 classes in target/classes/jdk7 and JDK8 classes in target/classes/jdk8.
The problem is that the "default-testCompile" execution of maven-compiler-plugin uses for classpath is :
- target/test-classes
- target/classes
- All dependencies jars
The compilation fails because maven-compiler-plugin is not looking for class files in the folder target/classes/jdk8.
I've tried to add compilerArguments & compilerArgs to the configuration but it didn't work...
How can i add "target/classes/jdk8" or change the "target/classes" to "target/classes/jdk8" to the classpath used by default-testCompile ?
Note : I know that if i don't disable the "default-compile", it will work because the classes will be in "target/classes" but i don't want to compile 3 times the sources...