Maven Eclipse set compiler JDK compliance level








The maven project/module created in Eclipse set JAVA 1.5 as the default. You cannot change it via Eclipse project settings (as it will be reverted back to 1.5) when you run Maven -> Update Project. To solve this, you can add the following to the pom.xml:
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>
Or, if you have hierarchical project with modules, you can put it into pluginManagement of the parent project's pom.xml:
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
All the descendant modules will inherit the compiler settings from the parent.

NOTE:

In Eclipse, if the project packaging is pom the compiler settings will not get updated using the above. You will need to change packaging to jar then Update the Maven projects. You can revert back to pom after the compiler settings has been changed.


No comments:

Post a Comment