Details

    • Type: Improvement Improvement
    • Status: Closed Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.3
    • Labels:
      None
    • Number of attachments :
      0

      Description

      Deafult source level setting for Maven compiler plugin is 1.3, as far as I remember. This makes no sense. 1.3 is used at this moment only in legacy applications. Probability of porting such legacy application to Maven 2 is very small. I was working with such applications - none of them used Maven. In fact, I don't know any application using Maven, which requires level 1.3.
      On the other hand, Maven is used exensively in new applications. Most of them use Java 5 features (annotations, generics...). All new applications I create use Maven 2 and Java 5. Every time I setup such application it makes me crazy that I get errors on my generics and annoations, and I have to setup manually the source level to 1.5. Come on, we have year 2008, not 2000! Java 5 is here for several years already. So why Maven compiler plugin does not use the most reasonable default approach, instead it still assumes we are in 2000 year? If someone wants to use old java version, than he can change the source level. By default should be 1.5.
      The default setting can be changed in never wersion of maven compiler plugin.

        Issue Links

          Activity

          Hide
          Marc Friedman added a comment -

          I am a new maven user and almost gave up on using it due to this one issue. I was trying to compile JAXB generated code and started getting the compiler error that 1.5 source requires 1.5 target. I have only Java 5 and Java 6 environments installed on my machine and the lack of any further diagnostic was driving me nuts. If maven is supposed to be about the benefits of convention over configuration, configuration should not be required in 2009 for the most basic task of compiling Java 5 source code!

          Show
          Marc Friedman added a comment - I am a new maven user and almost gave up on using it due to this one issue. I was trying to compile JAXB generated code and started getting the compiler error that 1.5 source requires 1.5 target. I have only Java 5 and Java 6 environments installed on my machine and the lack of any further diagnostic was driving me nuts. If maven is supposed to be about the benefits of convention over configuration, configuration should not be required in 2009 for the most basic task of compiling Java 5 source code!
          Hide
          Jesse Glick added a comment -

          #46 seems pretty similar.

          Show
          Jesse Glick added a comment - #46 seems pretty similar.
          Hide
          Mike R. Haller added a comment - - edited

          Do it now! Java 1.5 lifecycle is running out at the end of the year and Maven still uses 1.3 as default (according to compiler mojo project site). That's crazy!

          Show
          Mike R. Haller added a comment - - edited Do it now! Java 1.5 lifecycle is running out at the end of the year and Maven still uses 1.3 as default (according to compiler mojo project site). That's crazy!
          Hide
          Brett Porter added a comment -

          the reason this hasn't happened so far is that it might break builds (current or historical) that didn't lock in a version for the plugin and rely on the defaults.

          Show
          Brett Porter added a comment - the reason this hasn't happened so far is that it might break builds (current or historical) that didn't lock in a version for the plugin and rely on the defaults.
          Hide
          Grzegorz Borkowski added a comment -

          Well, does it mean that in year 2020, when nobody's gonna remember what Java 1.3 was, Maven will still assume default compile level to be 1.3? That's crazy.
          I understand backward compatibility, but it's crazy anyway.

          Show
          Grzegorz Borkowski added a comment - Well, does it mean that in year 2020, when nobody's gonna remember what Java 1.3 was, Maven will still assume default compile level to be 1.3? That's crazy. I understand backward compatibility, but it's crazy anyway.
          Hide
          Nikola Milutinovic added a comment -

          FYI, version set in super POM version 11 is "1.4":

          <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>2.0.2</version>
          <configuration>
          <source>1.4</source>
          <target>1.4</target>
          <encoding>$

          {project.build.sourceEncoding}

          </encoding>
          </configuration>
          </plugin>

          But still, it makes sense to have a new super POM that will set 1.5 and have new versions of Maven use that super POM. Anyone who wants to have 1.4 can set it in their POMs.

          Those who cannot alter (their) POMs and need 1.4 should stay with old versions of Maven. If you have a project "that works and should not be <<fixed>>", well, then don't "fix" it. Stay with Maven that worked for it.

          Show
          Nikola Milutinovic added a comment - FYI, version set in super POM version 11 is "1.4": <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.0.2</version> <configuration> <source>1.4</source> <target>1.4</target> <encoding>$ {project.build.sourceEncoding} </encoding> </configuration> </plugin> But still, it makes sense to have a new super POM that will set 1.5 and have new versions of Maven use that super POM. Anyone who wants to have 1.4 can set it in their POMs. Those who cannot alter (their) POMs and need 1.4 should stay with old versions of Maven. If you have a project "that works and should not be <<fixed>>", well, then don't "fix" it. Stay with Maven that worked for it.
          Hide
          Nikola Milutinovic added a comment -

          On the side note, just releasing the new super POM could be all we need, so we can set that to be the parent of our projects, until new version of Maven, using that POM, is out.

          Show
          Nikola Milutinovic added a comment - On the side note, just releasing the new super POM could be all we need, so we can set that to be the parent of our projects, until new version of Maven, using that POM, is out.
          Hide
          Stevo Slavic added a comment -

          Why not go all the way and set 1.6 as default, since "J2SE 5.0 will reach its end of service life (EOSL) on October 30th, 2009."?

          Show
          Stevo Slavic added a comment - Why not go all the way and set 1.6 as default, since "J2SE 5.0 will reach its end of service life (EOSL) on October 30th, 2009."?
          Hide
          Grzegorz Borkowski added a comment -

          Well, I reported this issue almost one year ago... perhaps at this moment 1.6 would be a better default value.
          Anyway, the difference between 1.5 and 1.6 is not that big. 1.5 is crucial, because all things that everybody use today: annotations, generics etc require at least 1.5.

          BTW: simply releasing new super POM would be good, but not change the thing: if I have to explicitly specify new super POM instead of explicitly specifying compiler plugin settings, that's not big win...

          Show
          Grzegorz Borkowski added a comment - Well, I reported this issue almost one year ago... perhaps at this moment 1.6 would be a better default value. Anyway, the difference between 1.5 and 1.6 is not that big. 1.5 is crucial, because all things that everybody use today: annotations, generics etc require at least 1.5. BTW: simply releasing new super POM would be good, but not change the thing: if I have to explicitly specify new super POM instead of explicitly specifying compiler plugin settings, that's not big win...
          Hide
          Jesse Glick added a comment -

          The difference between <source>1.5</source> and <source>1.6</source> is indeed relatively minor: semantics of @Override. However the difference between <target>1.5</target> and <target>1.6</target> is more important: Java 6 introduced the split-verifier bytecode format which is significantly faster to load. Command-line tools and desktop applications (for which load time is crucial) intended for use on Java 6 will be unnecessarily slow if compiled using <target>1.5</target>.

          Show
          Jesse Glick added a comment - The difference between <source>1.5</source> and <source>1.6</source> is indeed relatively minor: semantics of @Override. However the difference between <target>1.5</target> and <target>1.6</target> is more important: Java 6 introduced the split-verifier bytecode format which is significantly faster to load. Command-line tools and desktop applications (for which load time is crucial) intended for use on Java 6 will be unnecessarily slow if compiled using <target>1.5</target>.
          Hide
          Mike R. Haller added a comment -

          Who can we ping to update the super POM to be included in new maven versions?

          Show
          Mike R. Haller added a comment - Who can we ping to update the super POM to be included in new maven versions?
          Hide
          Chris Steinhoff added a comment -

          I know setting source and target is configuring a plugin, not maven, but could there be a way to set source and target in settings.xml? That way, the 3 people still using 1.3 don't have to change anything and the rest of us can set the default to 1.5. Maybe add a plugins tag to the settings schema? Or create a new pom-settings.xml file?

          Show
          Chris Steinhoff added a comment - I know setting source and target is configuring a plugin, not maven, but could there be a way to set source and target in settings.xml? That way, the 3 people still using 1.3 don't have to change anything and the rest of us can set the default to 1.5. Maybe add a plugins tag to the settings schema? Or create a new pom-settings.xml file?
          Hide
          Milos Kleint added a comment -

          what old version of maven will actually be affected? meaning which one doesn't set version numbers in super pom? 2.0.9 or older?

          There is one big problem with the super-pom solution and that's embedding and IDE usage. So we might end up with the IDE resolving the version differently than the cmd maven being used later for building. Or the IDE somehow makes use of the super-pom of the cmd-line maven being setup in the IDE. And then your newly created quickstart archetype will be either 1.4 or 1.5 depending on what cmd maven is on PATH?
          In the case when we only change the default value in compiler plugin, the IDE can figure the default value based on the version of the compiler plugin being used.

          Show
          Milos Kleint added a comment - what old version of maven will actually be affected? meaning which one doesn't set version numbers in super pom? 2.0.9 or older? There is one big problem with the super-pom solution and that's embedding and IDE usage. So we might end up with the IDE resolving the version differently than the cmd maven being used later for building. Or the IDE somehow makes use of the super-pom of the cmd-line maven being setup in the IDE. And then your newly created quickstart archetype will be either 1.4 or 1.5 depending on what cmd maven is on PATH? In the case when we only change the default value in compiler plugin, the IDE can figure the default value based on the version of the compiler plugin being used.
          Hide
          Milos Kleint added a comment -

          BTW this is by far the most voted on issue in MCOMPILER.

          Show
          Milos Kleint added a comment - BTW this is by far the most voted on issue in MCOMPILER.
          Hide
          redstun added a comment -

          I think the default source and target level for maven compiler should be the same as that of the java being used to invoke Maven.

          i.e.
          java 1.4 => source 1.4, target 1.4
          java 1.5 => source 1.5, target 1.5
          java 1.6 => source 1.6, target 1.6

          that is to say maven should follow the default source/target level settings in javac, as in the blog
          http://blogs.sun.com/darcy/entry/source_target_class_file_version of Joseph D. Darcy.

          Default javac Source and Target Settings

          JDK 1.4.0 and 1.4.1 only accepted source 1.3 and 1.4.
          JDK/J2SDK Default Source Source Range Default Target Target Range
          1.0.x 1.0 1.1
          1.1.x 1.1 1.1
          1.2.x 1.2 1.1 1.1 - 1.2
          1.3.x 1.2/1.3 1.1 1.1 - 1.3
          1.4.x 1.2/1.3 1.2 - 1.4 1.2 1.1 - 1.4
          5 1.5 1.2 - 1.5 1.5 1.1 - 1.5
          6 1.5 1.2 - 1.6 1.6 1.1 - 1.6
          7 1.7 1.2 - 1.7 1.7 1.1 - 1.7

          Show
          redstun added a comment - I think the default source and target level for maven compiler should be the same as that of the java being used to invoke Maven. i.e. java 1.4 => source 1.4, target 1.4 java 1.5 => source 1.5, target 1.5 java 1.6 => source 1.6, target 1.6 that is to say maven should follow the default source/target level settings in javac, as in the blog http://blogs.sun.com/darcy/entry/source_target_class_file_version of Joseph D. Darcy. Default javac Source and Target Settings JDK 1.4.0 and 1.4.1 only accepted source 1.3 and 1.4. JDK/J2SDK Default Source Source Range Default Target Target Range 1.0.x 1.0 1.1 1.1.x 1.1 1.1 1.2.x 1.2 1.1 1.1 - 1.2 1.3.x 1.2/1.3 1.1 1.1 - 1.3 1.4.x 1.2/1.3 1.2 - 1.4 1.2 1.1 - 1.4 5 1.5 1.2 - 1.5 1.5 1.1 - 1.5 6 1.5 1.2 - 1.6 1.6 1.1 - 1.6 7 1.7 1.2 - 1.7 1.7 1.1 - 1.7
          Hide
          Jesse Glick added a comment -

          Using default source/target levels in a build tool is not a good idea since it makes both the success of the build and its artifacts dependent on the environment in which it was run, contrary to the goals of a reproducible build. A given module or tree of modules will have a certain source level it requires in order to compile, so increments to this in the POM should be coversioned with source code changes to use new language features. Target level (usually but not necessarily the same as source level) is even more important to specify explicitly, because it is not obvious when you get it wrong - until your bytecode fails to load on an older customer JVM which you had intended to still support (perhaps using animal-sniffer to cover JRE API level), or (even less obviously) because target=5 bytecode loads unnecessarily slowly on a 6+ JVM.

          Show
          Jesse Glick added a comment - Using default source/target levels in a build tool is not a good idea since it makes both the success of the build and its artifacts dependent on the environment in which it was run, contrary to the goals of a reproducible build. A given module or tree of modules will have a certain source level it requires in order to compile, so increments to this in the POM should be coversioned with source code changes to use new language features. Target level (usually but not necessarily the same as source level) is even more important to specify explicitly, because it is not obvious when you get it wrong - until your bytecode fails to load on an older customer JVM which you had intended to still support (perhaps using animal-sniffer to cover JRE API level), or (even less obviously) because target=5 bytecode loads unnecessarily slowly on a 6+ JVM.
          Hide
          Grzegorz Borkowski added a comment -

          I agree with Jesse. Builds should be portable and reproducible, and using JVM defaults isn't.
          BTW we are in 2010 now, so the title of this issue should be definitely changed to "Change default source level to 1.6", as Java 6 was released more than 3 years ago, and is the default platform nowadays. On the other hand, I reported this issue more almost 1.5 years ago, and no progress has been made since that time. So I guess that my vision of having java 1.3 as the default in maven compilier in year 2020 is getting more and more realistic...

          Show
          Grzegorz Borkowski added a comment - I agree with Jesse. Builds should be portable and reproducible, and using JVM defaults isn't. BTW we are in 2010 now, so the title of this issue should be definitely changed to "Change default source level to 1.6", as Java 6 was released more than 3 years ago, and is the default platform nowadays. On the other hand, I reported this issue more almost 1.5 years ago, and no progress has been made since that time. So I guess that my vision of having java 1.3 as the default in maven compilier in year 2020 is getting more and more realistic...
          Hide
          redstun added a comment -

          Grzegorz, it's interesting to read your comments, thanks.

          Let's do it this way.

          1. defaulting to 1.3 as the source and 1.1 as the target is already a problem for now
          2. defaulting to another reasonable (for now) source/target levels is can fix the problem for the current mainstream ecosystem, but will be again a problem later, e.g. in the year 2020.

          And, a quite common 'convention' is that people always assume things we've got for now should work 'for now', Maven as a mainstream Java build tool should always work for the mainstream Java platform with no extra configuration.

          One of the best values of Maven is convention over configuration, compared to Ant. Interestingly enough, Even Ant is delegating to the JVM that is running Ant to determine the source/target levels. See http://ant.apache.org/manual/CoreTasks/javac.html

          For enterprise development, source/target levels should be seriously set regardless what the default values are, but for most developers, people are just using the mainstream platform, e.g. the latest JDK/JRE and just want to compile for the mainstream JRE, only when one want to compile for a specific version of JRE, then it becomes necessary to specify the source/target levels.

          Thanks

          Show
          redstun added a comment - Grzegorz, it's interesting to read your comments, thanks. Let's do it this way. 1. defaulting to 1.3 as the source and 1.1 as the target is already a problem for now 2. defaulting to another reasonable (for now) source/target levels is can fix the problem for the current mainstream ecosystem, but will be again a problem later, e.g. in the year 2020. And, a quite common 'convention' is that people always assume things we've got for now should work 'for now', Maven as a mainstream Java build tool should always work for the mainstream Java platform with no extra configuration. One of the best values of Maven is convention over configuration, compared to Ant. Interestingly enough, Even Ant is delegating to the JVM that is running Ant to determine the source/target levels. See http://ant.apache.org/manual/CoreTasks/javac.html For enterprise development, source/target levels should be seriously set regardless what the default values are, but for most developers, people are just using the mainstream platform, e.g. the latest JDK/JRE and just want to compile for the mainstream JRE, only when one want to compile for a specific version of JRE, then it becomes necessary to specify the source/target levels. Thanks
          Hide
          Jesse Glick added a comment -

          It is true that for historical reasons Ant picks a default source/target level according to the JVM. The manual warns you against doing this in boldface.

          (Note that I have no problem with picking up a JVM-specific source/target level in an archetype. This is run just once, not as part of a reproducible build.)

          Show
          Jesse Glick added a comment - It is true that for historical reasons Ant picks a default source/target level according to the JVM. The manual warns you against doing this in boldface. (Note that I have no problem with picking up a JVM-specific source/target level in an archetype . This is run just once, not as part of a reproducible build.)
          Hide
          redstun added a comment -

          IMHO, for this, Ant is doing the right thing, the warning is actually also what Maven needs to have, to allow the user use the platform default source/target levels, but warn the user that it's always necessary to specify the expected source/target levels.

          Maven, as a tool/library, should warn the user to explicitly set source/target levels, instead of doing it FOR the user, because whatever it does for the user, will always be wrong in a different context.

          Another point is that, the user is responsible for which version of Java (and the source/target levels) to use. The Java version, as part of the platform information, should always be reported by the user, not decided by Maven to have a reproducible build.

          Thanks

          Show
          redstun added a comment - IMHO, for this, Ant is doing the right thing, the warning is actually also what Maven needs to have, to allow the user use the platform default source/target levels, but warn the user that it's always necessary to specify the expected source/target levels. Maven, as a tool/library, should warn the user to explicitly set source/target levels, instead of doing it FOR the user, because whatever it does for the user, will always be wrong in a different context. Another point is that, the user is responsible for which version of Java (and the source/target levels) to use. The Java version, as part of the platform information, should always be reported by the user, not decided by Maven to have a reproducible build. Thanks
          Hide
          Benjamin Bentmann added a comment -

          Done in r932664.

          Show
          Benjamin Bentmann added a comment - Done in r932664 .
          Hide
          Grzegorz Borkowski added a comment -

          I see it was fixed, setting default value to 1.5.
          However, I'm not that sure if it's the best choice, so I reopen it again for discussion. I reported this issue in 2008. At that time it seemed to me to be the logical value. However, if we fix it in 2010, the most logical value is 1.6, I think. Java 5 was scheduled to end-of-live in 2009, if I remember correctly. Java 6 is stable and mature. Probably 99% of projects starting in year 2010 will use Java 6, so they will have to override this setting anyway. The sense of "default" value is that most of people will not have to change it. In this context, if everybody is going to change it to 1.6 anyway, than it has no sense at all.
          I've just checked the project I'm working on now. It has compiler level set to 1.6. Probably, two years ago when this issue was reported, it was 1.5.
          As the Java 7 is not that likely in the near future to come (I'm not the best informed guy on this topic, but that's the popular feeling I think), than using 1.6 as default value has a chance to be valid for several years.

          Show
          Grzegorz Borkowski added a comment - I see it was fixed, setting default value to 1.5. However, I'm not that sure if it's the best choice, so I reopen it again for discussion. I reported this issue in 2008. At that time it seemed to me to be the logical value. However, if we fix it in 2010, the most logical value is 1.6, I think. Java 5 was scheduled to end-of-live in 2009, if I remember correctly. Java 6 is stable and mature. Probably 99% of projects starting in year 2010 will use Java 6, so they will have to override this setting anyway. The sense of "default" value is that most of people will not have to change it. In this context, if everybody is going to change it to 1.6 anyway, than it has no sense at all. I've just checked the project I'm working on now. It has compiler level set to 1.6. Probably, two years ago when this issue was reported, it was 1.5. As the Java 7 is not that likely in the near future to come (I'm not the best informed guy on this topic, but that's the popular feeling I think), than using 1.6 as default value has a chance to be valid for several years.
          Hide
          Benjamin Bentmann added a comment -

          For the upcoming plugin release, it is 1.5/1.5, please open another issue for 1.6.

          Show
          Benjamin Bentmann added a comment - For the upcoming plugin release, it is 1.5/1.5, please open another issue for 1.6.
          Hide
          Grzegorz Borkowski added a comment -

          Well, I can do it, but I don't understand... you could change it to 1.5 from 1.3 after so many years, and now you can't modify this fix? what's the problem with this? And what's the point of releasing new version of plugin with default set to 1.5 after so many years, only to change it 1.6 soon?

          Show
          Grzegorz Borkowski added a comment - Well, I can do it, but I don't understand... you could change it to 1.5 from 1.3 after so many years, and now you can't modify this fix? what's the problem with this? And what's the point of releasing new version of plugin with default set to 1.5 after so many years, only to change it 1.6 soon?
          Hide
          redstun added a comment - - edited

          We can see here that soon after the request (to default to 1.5) was fixed, we got a new request to change it again. Over time, this will be endless.

          To really have this issue fixed, in a proper way, I've filed the all-in-one issue MCOMPILER-125, that Maven should follow Ant and Eclipse to default the source/target levels to the JDK being used.

          To express your opinion/idea, please see MCOMPILER-125 and comment there.

          Thanks

          Show
          redstun added a comment - - edited We can see here that soon after the request (to default to 1.5) was fixed, we got a new request to change it again. Over time, this will be endless. To really have this issue fixed, in a proper way, I've filed the all-in-one issue MCOMPILER-125 , that Maven should follow Ant and Eclipse to default the source/target levels to the JDK being used. To express your opinion/idea, please see MCOMPILER-125 and comment there. Thanks

            People

            • Assignee:
              Jason van Zyl
              Reporter:
              Grzegorz Borkowski
            • Votes:
              44 Vote for this issue
              Watchers:
              16 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: