Skip to content
Advertisement

maven-compiler-plugin broken on linux?

I have a maven project. In the pom.xml file the following is stated:

...
<build>
    <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.1</version>
          <configuration>
            <source>1.7</source>
            <target>1.7</target>
          </configuration>
        </plugin>
        ...
    </plugins>
</build>
...

AFAIK this is correct, it should build against JDK 7.

I run a Debian based Linux dist and when I do mvn clean install it seems to always build against the javac version I have set in my os.

I’ve tried reading up on what the plugin exactly does https://maven.apache.org/plugins/maven-compiler-plugin/, but it doesn’t really state how.

An example is I have javac 8 running on my os. When I invoke mvn clean install, the project compiles against JDK 8 and not JDK 7 as stated in the pom.xml. Why is this?

Advertisement

Answer

By default the maven-compiler-plugin uses %JAVA_HOME%/bin/javac to compile, unless:

  • you set the executable-parameter to a different location
  • you use Toolchains, which seems to match your requirements, i.e a different Java Runtime for Maven compared to the JDK for the maven-compiler-plugin.
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement