Maven Compiler Plugin
  1. Maven Compiler Plugin
  2. MCOMPILER-125

Maven should not set default Java source target level

    Details

    • Type: Improvement Improvement
    • Status: Open Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.0, 2.0.1, 2.0.2, 2.1, 2.2
    • Fix Version/s: None
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Expectation:
      The Maven Compiler Plugin, as it is just a wrapper of the underlying compiler (javac by default), should not change the default source/target levels of the underlying compiler, or specifying any hard coded values, FOR the user.

      Fact:
      As described in the plugin homepage (http://maven.apache.org/plugins/maven-compiler-plugin/index.html), "The default source setting is 1.3 and the default target setting is 1.1, independently of the JDK you run Maven with."
      And people have been complaining against this, For that the default source/target levels are either inappropriate or outdated. See MCOMPILER-80, MCOMPILER-46, MCOMPILER-124. Plus that MCOMPILER-80 has been re-opened recently soon after it's fixed.
      Up to now, the filed issues are all about to change the default source/target levels to more 'current' values, but whatever the values are set to, they will sooner or later fall out of date, this is why we have several requests like this over time, as listed above. They all represent a resolution for 'now', not for all the time.
      On the contrary, Ant is doing this as expected, As in http://ant.apache.org/manual/CoreTasks/javac.html, it always defaults the source/target levels to the javac in use, and clarifies that the users are "highly recommended to always specify them".
      And As a result, Ant never gets complaints regarding the issues we filed against Maven Compiler Plugin.
      Additionally, Eclipse is using the default values from the JDK in use as well. if we create a project with mvn archetype:generate, then mvn eclipse:eclipse and import it into Eclipse, you'll see that Eclipse does it like Ant. Keep the project open in Eclipse and do a mvn compile outside (or phases that depend on it, such as mvn package), you'll see a weird compile error in Eclipse with no obvious clue. At the beginning you won't 'see' that the problem is caused by Maven, to be specific, the source/target levels set by Maven FOR you.

        Activity

        Hide
        Antony Stubbs added a comment -

        I think I'd rather have an out of date level set, rather than have it change on different computers / jdks's.

        Perhaps make it a top level configuration in the pom? That way it would be less pain to specify it. Especially if you're going to make it "dynamic".
        <project>
        <sourceLevel>1.5<sourceLevel>
        </project>

        Show
        Antony Stubbs added a comment - I think I'd rather have an out of date level set, rather than have it change on different computers / jdks's. Perhaps make it a top level configuration in the pom? That way it would be less pain to specify it. Especially if you're going to make it "dynamic". <project> <sourceLevel>1.5<sourceLevel> </project>
        Hide
        redstun added a comment -

        As the issue reporter, I'd like to add a note.

        I'm not saying it's unnecessary to have specified source/target levels. On the contrary, this is very necessary or a must.

        Just that, the source/target levels should be decided by its owners/developers, NOT BY Maven. It's the project owner/developer's responsibility to decided the expected source/target levels and set the values in the project POM. Thus to have reproducible builds across computers/jdks.

        There has been a similar issue about how to handle the resource encoding in Maven, which had also gone through a lot of discussions. It finally become clear that there should be a place in project POM to let the project owner/developers configure the desired project level source encoding, instead of allowing each Maven plugin to have its own default encoding. We can learn from the conclusion there. For this please refer to http://docs.codehaus.org/display/MAVENUSER/POM+Element+for+Source+File+Encoding

        Thanks

        Show
        redstun added a comment - As the issue reporter, I'd like to add a note. I'm not saying it's unnecessary to have specified source/target levels. On the contrary, this is very necessary or a must. Just that, the source/target levels should be decided by its owners/developers, NOT BY Maven. It's the project owner/developer's responsibility to decided the expected source/target levels and set the values in the project POM. Thus to have reproducible builds across computers/jdks. There has been a similar issue about how to handle the resource encoding in Maven, which had also gone through a lot of discussions. It finally become clear that there should be a place in project POM to let the project owner/developers configure the desired project level source encoding, instead of allowing each Maven plugin to have its own default encoding. We can learn from the conclusion there. For this please refer to http://docs.codehaus.org/display/MAVENUSER/POM+Element+for+Source+File+Encoding Thanks
        Hide
        redstun added a comment -

        The subject of this issue should have been

        • Maven should respect platform default source/target levels and warn the user to explicitly set them.

        Show
        redstun added a comment - The subject of this issue should have been Maven should respect platform default source/target levels and warn the user to explicitly set them.

          People

          • Assignee:
            Unassigned
            Reporter:
            redstun
          • Votes:
            5 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

            • Created:
              Updated: