dushkin
dushkin

Reputation: 2101

Setting jdk version in eclipse maven project

I a new "mavenist"... :-)

I work with Eclipse Mars.

I created a default maven project, and it uses JDK 1.5 by default. I would like to use 1.8.31 instead.

My current POM shows the following:

   <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <executions>
      <execution>
        <id>default-compile</id>
        <phase>compile</phase>
        <goals>
          <goal>compile</goal>
        </goals>
      </execution>
      <execution>
        <id>default-testCompile</id>
        <phase>test-compile</phase>
        <goals>
          <goal>testCompile</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

On apache maven website I read that I need to change\replace it to something like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.3</version>
    <configuration>
      <verbose>true</verbose>
      <fork>true</fork>
      <executable><!-- path-to-javac --></executable>
      <compilerVersion>1.8.31</compilerVersion>
    </configuration>
  </plugin>
  1. Is this the right code to put?
  2. Should it replace the current code, or should I add it to the xml?

Thank you!

Upvotes: 1

Views: 2415

Answers (2)

Ravi K Thapliyal
Ravi K Thapliyal

Reputation: 51711

You're on the right track but just override the options that you need to.

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

Repeating verbose, fork, executable etc. isn't required.

Upvotes: 3

Myzreal
Myzreal

Reputation: 351

This should be enough, taken from my very recent project.

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
</plugin>

Upvotes: 2

Related Questions