Issue
I have a project with one main module that use pom
packaging and several submodules that are defined to use jar
packaging. I want to have some of them ready to run on JDK7 and other for JDK8 (and eventually embed those for JDK7 as dependencies in the JDK8 counterpart).
The goal is to release the submodules as independent jars (e.g. on Maven Central)
Is this approach correct? Any drawback?
Solution
You can use the toolchains plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>${java.min.version}</version>
<vendor>oracle</vendor>
</jdk>
</toolchains>
</configuration>
</plugin>
You need to have a toolchains file which configures the toolchains you want to use: https://maven.apache.org/plugins/maven-toolchains-plugin/toolchains/jdk.html
You also need to specify the java version in the compiler plugin etc.
Answered By - Puce
Answer Checked By - Timothy Miller (JavaFixing Admin)