This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 236391 - (maven) use the new "properties" method for specifying the source/binary format
Summary: (maven) use the new "properties" method for specifying the source/binary format
Status: VERIFIED FIXED
Alias: None
Product: projects
Classification: Unclassified
Component: Maven (show other bugs)
Version: 7.4
Hardware: All All
: P3 normal (vote)
Assignee: Tomas Stupka
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-26 02:09 UTC by athompson
Modified: 2015-02-22 03:27 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description athompson 2013-09-26 02:09:17 UTC
Currently, when you set the source/binary format of a Maven project via the project properties, it adds something like this to your "pom.xml" file:

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

Consider instead using this form where possible:

  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

The latter version has the advantage that you don't have to explicitly specify the Maven compiler plugin version, providing more flexibility in some parent/child pom setups.

I imagine if a pom file already specifies a compiler plugin version which predates this property (the Maven docs say it has been there since 2.0), you'll need to fall back to the original method. Of course, if there's some reason I'm not thinking of where the current method is a better choice, feel free to close this. The only reason I can think of is if older plugin versions don't support newer JDKs (I don't see why they would not).
Comment 1 athompson 2013-09-26 02:20:25 UTC
I should mention that Netbeans Maven projects already seems to understand the latter format if you manually add it to your pom file.
Comment 2 Milos Kleint 2013-09-30 13:27:24 UTC
we explicitly write the <configuration> section as that's the most deterministic thing to do. Once <configuration> parameter is written somewhere (this pom, any of the parents, profiles etc) the property maven.compiler.source will *not* be used. So we are defending against writing a value that's not picked up by the resolved model (making it a noop).

in general writing to pom in a way that is both generic and observant to what's already written in the pom (and the parents) is fairly hard and we try to avoid it.
Comment 3 terje7601 2015-02-15 08:16:54 UTC
This issue is resolved, isn't it? When I create a new Maven project, it has the section:

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <maven.compiler.source>1.7</maven.compiler.source>
  <maven.compiler.target>1.7</maven.compiler.target>
</properties>
Comment 4 athompson 2015-02-22 03:26:52 UTC
Yup.