I'm using scala-maven-plugin
to build a Scala project using Maven. My project depends on some libraries from Java 8. I would like to specify in my pom that the project requires Java 8 (using something akin to -target=jdk-1.8
, which appears not to exist) so that it will fail a little more elegantly/informatively when someone tries to compile using Java version < 8. Currently it just fails to find the packages I'm trying to import.
I tried adding maven-compiler-plugin
with source
and target
set to 1.8, and this didn't work, presumably because scala-maven-plugin
is handling compilation instead of maven-compiler-plugin
.
Is this possible?
You can use Maven Enforcer Plugin to enforce some rules to be asserted when running your Maven build.
Here you want to make sure that the Java
version used is at least 8
. You can achieve this by adding the following to your pom.xml
file:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>enforce-java</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>[1.8,)</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>