You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Gisbert Amm <gi...@webde.de> on 2007/08/15 16:27:15 UTC

Why does Maven2 by default generate Java 1.1 byte code?

Searching for version issues, I had a closer look at the *.class files 
generated by Maven2 with the default compiler settings and found that 
the first bytes of them are "cafe babe 0003 002D ...", which is byte 
code version 45.3 = Java 1.1.

First I was believing that I had this (target 1.1) configured somewhere 
by accident. However, I didn't find any such configuration, therefore I 
dug into the plexus-compiler source and found the following in 
plexus-site/plexus-components/plexus-compiler/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java:

   // TODO: this could be much improved
         if ( StringUtils.isEmpty( config.getTargetVersion() ) )
         {
             // Required, or it defaults to the target of your JDK (eg 1.5)
             args.add( "-target" );
             args.add( "1.1" );
         }
         else
         {
             args.add( "-target" );
             args.add( config.getTargetVersion() );
         }

         if ( !suppressSource( config ) && StringUtils.isEmpty( 
config.getSourceVersion() ) )
         {
             // If omitted, later JDKs complain about a 1.1 target
             args.add( "-source" );
             args.add( "1.3" );
         }

Is there any particular reason why target is set to 1.1 here? IMHO, it 
breaks the rule of least surprise for I am certainly expecting that the 
generated byte code by default has the version of the JDK I'm using the 
compiler of. The comment "Required, or it defaults to the target of your 
JDK" doesn't give any reason. Does anybody know, why this default is set?

At least it should be mentioned on 
http://maven.apache.org/plugins/maven-compiler-plugin/howto.html to make 
it obvious to users. Otherwise people might have problems and need a 
long time to find out what's going on (see 
http://www.nabble.com/Odd-Compilation-Issue-tf1566644s177.html#a4287495 
for an example).

Regards,
Gisbert

-- 
Gisbert Amm
Softwareentwickler Infrastruktur

WEB.DE GmbH
Brauerstraße 48 · D-76135 Karlsruhe
Tel. +49-721-91374-4224 · Fax +49-721-91374-2740
gisbert.amm@webde.de · http://www.web.de/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Why does Maven2 by default generate Java 1.1 byte code?

Posted by Wayne Fay <wa...@gmail.com>.
I haven't performed a complete, in-depth historical analysis of every
thread involving compiler defaults to find all the discussions of this
issue, but here are 2 email threads you can refer to...

from   David Smith <>
to   users@maven.apache.org
date  May 4, 2007 9:46 AM
subject  Maven 2.0.6 using JDK 1.3
(specifically, my email to paul g)

from   Brett Porter <>
to   dev@maven.apache.org
date  Jul 6, 2006 8:36 PM
subject  [discuss] Java 5
(a lengthy discussion on moving Maven2 to Jdk5 -- note this is the dev list)

When considering the "compiler defaults should be my current JDK
version" issue, there are a lot of other things to consider. Please
read my response to Paul in particular and think about all the issues
before simply assuming Maven should work the way you expected.

Wayne

On 8/16/07, Gisbert Amm <gi...@webde.de> wrote:
> Wayne Fay wrote:
> > This has been discussed several times on this list.
>
> Sorry, I haven't found these discussions, neihter by searching for
> "compiler defaults" nor by searching for "byte code [version]"
>
> > IMO, the default compilation target being 1.1 (or another hard-defined
> > version) meets the rule of least surprise. You can argue that you
> > don't like 1.1 and you'd prefer 1.3 or even 1.5 but that is another
> > discussion.
> >
> > In contrast, the rule of most surprise would be "my build changes when
> > I change my JDK" or "my build changes when I build things on different
> > machines". This is the absolute worst thing you can run into when
> > trying to standardize and control your build process.
>
> I disagree on that. For me it is not surprising at all that my build
> changes when I use a different compiler. At the contrary, under certain
> cirumstances I'd expect this and would be surprised if the build (or the
> result) would not change.
> When the build produces the same results in different environments, this
> can lead to hard-to-find problems later on. I still think it would be
> better if the Maven compiler would produce byte code matching the
> version of the JDK Maven is running with. That's what I expect when I do
> a javac call and I don't see why Maven should silently change this
> behaviour.
> While this is not such a big issue (any JVM equal to or greater than 1.1
> can indeed exectute JVM 1.1 byte code and the cases where real problems
> occur might be rare) the source=1.3 default really surprises the user.
> When I create a new project and build it on Maven with a 1.5 JDK
> expecting Java 5 features to work, I get error messages like "generics
> are not supported in -source 1.3" and do not know where that comes from.
> At least that is not very user friendly and I suppose Maven wants to be
> user friendly and easy to use.
>
> > If you want to target a specific JDK, then simply add the compiler
> > configuration in your poms. If you feel this has not been documented
> > sufficiently,
>
> I did not say that *this* is not documented sufficiently, I did say that
> the defaults aren't documented at all.
>
> > then post a RFE in Jira and someone will add some text
> > to the proper page(s) on the site.
>
> Done. http://jira.codehaus.org/browse/MCOMPILER-57
>
> --
> Gisbert Amm
> Softwareentwickler Infrastruktur
>
> WEB.DE GmbH
> Brauerstraße 48 · D-76135 Karlsruhe
> Tel. +49-721-91374-4224 · Fax +49-721-91374-2740
> gisbert.amm@webde.de · http://www.web.de/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Why does Maven2 by default generate Java 1.1 byte code?

Posted by Gisbert Amm <gi...@webde.de>.
Wayne Fay wrote:
> This has been discussed several times on this list.

Sorry, I haven't found these discussions, neihter by searching for 
"compiler defaults" nor by searching for "byte code [version]"

> IMO, the default compilation target being 1.1 (or another hard-defined
> version) meets the rule of least surprise. You can argue that you
> don't like 1.1 and you'd prefer 1.3 or even 1.5 but that is another
> discussion.
> 
> In contrast, the rule of most surprise would be "my build changes when
> I change my JDK" or "my build changes when I build things on different
> machines". This is the absolute worst thing you can run into when
> trying to standardize and control your build process.

I disagree on that. For me it is not surprising at all that my build 
changes when I use a different compiler. At the contrary, under certain 
cirumstances I'd expect this and would be surprised if the build (or the 
result) would not change.
When the build produces the same results in different environments, this 
can lead to hard-to-find problems later on. I still think it would be 
better if the Maven compiler would produce byte code matching the 
version of the JDK Maven is running with. That's what I expect when I do 
a javac call and I don't see why Maven should silently change this 
behaviour.
While this is not such a big issue (any JVM equal to or greater than 1.1 
can indeed exectute JVM 1.1 byte code and the cases where real problems 
occur might be rare) the source=1.3 default really surprises the user. 
When I create a new project and build it on Maven with a 1.5 JDK 
expecting Java 5 features to work, I get error messages like "generics 
are not supported in -source 1.3" and do not know where that comes from. 
At least that is not very user friendly and I suppose Maven wants to be 
user friendly and easy to use.

> If you want to target a specific JDK, then simply add the compiler
> configuration in your poms. If you feel this has not been documented
> sufficiently, 

I did not say that *this* is not documented sufficiently, I did say that 
the defaults aren't documented at all.

> then post a RFE in Jira and someone will add some text
> to the proper page(s) on the site.

Done. http://jira.codehaus.org/browse/MCOMPILER-57

-- 
Gisbert Amm
Softwareentwickler Infrastruktur

WEB.DE GmbH
Brauerstraße 48 · D-76135 Karlsruhe
Tel. +49-721-91374-4224 · Fax +49-721-91374-2740
gisbert.amm@webde.de · http://www.web.de/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Why does Maven2 by default generate Java 1.1 byte code?

Posted by Wayne Fay <wa...@gmail.com>.
This has been discussed several times on this list.

IMO, the default compilation target being 1.1 (or another hard-defined
version) meets the rule of least surprise. You can argue that you
don't like 1.1 and you'd prefer 1.3 or even 1.5 but that is another
discussion.

In contrast, the rule of most surprise would be "my build changes when
I change my JDK" or "my build changes when I build things on different
machines". This is the absolute worst thing you can run into when
trying to standardize and control your build process.

If you want to target a specific JDK, then simply add the compiler
configuration in your poms. If you feel this has not been documented
sufficiently, then post a RFE in Jira and someone will add some text
to the proper page(s) on the site.

Wayne

On 8/15/07, Gisbert Amm <gi...@webde.de> wrote:
> Searching for version issues, I had a closer look at the *.class files
> generated by Maven2 with the default compiler settings and found that
> the first bytes of them are "cafe babe 0003 002D ...", which is byte
> code version 45.3 = Java 1.1.
>
> First I was believing that I had this (target 1.1) configured somewhere
> by accident. However, I didn't find any such configuration, therefore I
> dug into the plexus-compiler source and found the following in
> plexus-site/plexus-components/plexus-compiler/plexus-compilers/plexus-compiler-javac/src/main/java/org/codehaus/plexus/compiler/javac/JavacCompiler.java:
>
>   // TODO: this could be much improved
>         if ( StringUtils.isEmpty( config.getTargetVersion() ) )
>         {
>             // Required, or it defaults to the target of your JDK (eg 1.5)
>             args.add( "-target" );
>             args.add( "1.1" );
>         }
>         else
>         {
>             args.add( "-target" );
>             args.add( config.getTargetVersion() );
>         }
>
>         if ( !suppressSource( config ) && StringUtils.isEmpty(
> config.getSourceVersion() ) )
>         {
>             // If omitted, later JDKs complain about a 1.1 target
>             args.add( "-source" );
>             args.add( "1.3" );
>         }
>
> Is there any particular reason why target is set to 1.1 here? IMHO, it
> breaks the rule of least surprise for I am certainly expecting that the
> generated byte code by default has the version of the JDK I'm using the
> compiler of. The comment "Required, or it defaults to the target of your
> JDK" doesn't give any reason. Does anybody know, why this default is set?
>
> At least it should be mentioned on
> http://maven.apache.org/plugins/maven-compiler-plugin/howto.html to make
> it obvious to users. Otherwise people might have problems and need a
> long time to find out what's going on (see
> http://www.nabble.com/Odd-Compilation-Issue-tf1566644s177.html#a4287495
> for an example).
>
> Regards,
> Gisbert
>
> --
> Gisbert Amm
> Softwareentwickler Infrastruktur
>
> WEB.DE GmbH
> Brauerstraße 48 · D-76135 Karlsruhe
> Tel. +49-721-91374-4224 · Fax +49-721-91374-2740
> gisbert.amm@webde.de · http://www.web.de/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org