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 189496 - Support Maven toolchains and/or Animal Sniffer
Summary: Support Maven toolchains and/or Animal Sniffer
Status: NEW
Alias: None
Product: projects
Classification: Unclassified
Component: Maven (show other bugs)
Version: 6.x
Hardware: All All
: P3 normal with 4 votes (vote)
Assignee: Tomas Stupka
URL:
Keywords: PLAN
Depends on:
Blocks:
 
Reported: 2010-08-13 16:59 UTC by chrishhde
Modified: 2016-02-16 20:34 UTC (History)
3 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
Netbeans Maven project (11.68 KB, application/zip)
2010-08-13 17:09 UTC, chrishhde
Details

Note You need to log in before you can comment on or make changes to this bug.
Description chrishhde 2010-08-13 16:59:20 UTC
Read about Maven toolchains: http://maven.apache.org/guides/mini/guide-using-toolchains.html

It would be a nice feature, if Netbeans read the required JDK version from an existing pom.xml's toolchains configuration, instead of having to set compiler version manually for all Maven modules in a bigger project.

That way, a single configuration location would exist for a Maven project. The project could be fired both on command line as well as in your favourite IDE equally, without changing anything or having to configure multiple times.

See related bug: http://netbeans.org/bugzilla/show_bug.cgi?id=187120.


As many projects still depend on Java 5 (despite its EOSL) and newer Netbeans versions need Java 6, I'm sure many people fight with problems regarding different JDK versions.
Comment 1 chrishhde 2010-08-13 17:04:07 UTC
Attached you find a very small and simple Netbeans Maven project.

When you run it without explicitly setting the JDK version in project settings, the build will roundabout show like this: (using Ubuntu 10.04)


NetBeans: Executing '/usr/share/maven2/bin/mvn -Dnetbeans.execution=true clean install'
NetBeans:      JAVA_HOME=/usr/lib/jvm/java-6-sun
Scanning for projects...
------------------------------------------------------------------------
Building BugNetbeans
   task-segment: [clean, install]
------------------------------------------------------------------------
[clean:clean]
Deleting directory /home/user/BugNetbeans/target
[toolchains:toolchain]
Type:jdk
Toolchain (jdk) matched:JDK[/opt/jdk1.5.0_22]
[resources:resources]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
skip non existing resourceDirectory /home/user/BugNetbeans/src/main/resources
[compiler:compile]
Compiling 1 source file to /home/user/BugNetbeans/target/classes
[resources:testResources]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
skip non existing resourceDirectory /home/user/BugNetbeans/src/test/resources
[compiler:testCompile]
Compiling 1 source file to /home/user/BugNetbeans/target/test-classes
[surefire:test]
Toolchain in surefire-plugin: JDK[/opt/jdk1.5.0_22]
Surefire report directory: /home/user/BugNetbeans/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.mycompany.bugnetbeans.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.022 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[jar:jar]
Building jar: /home/user/BugNetbeans/target/BugNetbeans-1.0-SNAPSHOT.jar
[install:install]
Installing /home/user/BugNetbeans/target/BugNetbeans-1.0-SNAPSHOT.jar to /home/user/.m2/com/mycompany/BugNetbeans/1.0-SNAPSHOT/BugNetbeans-1.0-SNAPSHOT.jar
------------------------------------------------------------------------
BUILD SUCCESSFUL
------------------------------------------------------------------------
Total time: 3 seconds
Finished at: Fri Aug 13 18:43:09 CEST 2010
Final Memory: 40M/730M
------------------------------------------------------------------------
Comment 2 chrishhde 2010-08-13 17:06:37 UTC
Instead I would like to see this behaviour - without having to set Source/Binary Format and Compile - Java Platform manually in the project settings:

NetBeans: Executing '/usr/share/maven2/bin/mvn -Dnetbeans.execution=true clean install'
NetBeans:      JAVA_HOME=/opt/jdk1.5.0_22
Scanning for projects...
------------------------------------------------------------------------
Building BugNetbeans
   task-segment: [clean, install]
------------------------------------------------------------------------
[clean:clean]
Deleting directory /home/user/BugNetbeans/target
[toolchains:toolchain]
Type:jdk
Toolchain (jdk) matched:JDK[/opt/jdk1.5.0_22]
[resources:resources]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources,
i.e. build is platform dependent!
skip non existing resourceDirectory /home/user/BugNetbeans/src/main/resources
[compiler:compile]
Compiling 1 source file to /home/user/BugNetbeans/target/classes
[resources:testResources]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources,
i.e. build is platform dependent!
skip non existing resourceDirectory /home/user/BugNetbeans/src/test/resources
[compiler:testCompile]
Compiling 1 source file to /home/user/BugNetbeans/target/test-classes
[surefire:test]
Toolchain in surefire-plugin: JDK[/opt/jdk1.5.0_22]
Surefire report directory: /home/user/BugNetbeans/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.mycompany.bugnetbeans.AppTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.022 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[jar:jar]
Building jar: /home/user/BugNetbeans/target/BugNetbeans-1.0-SNAPSHOT.jar
[install:install]
Installing /home/user/BugNetbeans/target/BugNetbeans-1.0-SNAPSHOT.jar to
/home/user/.m2/com/mycompany/BugNetbeans/1.0-SNAPSHOT/BugNetbeans-1.0-SNAPSHOT.jar
------------------------------------------------------------------------
BUILD SUCCESSFUL
------------------------------------------------------------------------
Total time: 3 seconds
Finished at: Fri Aug 13 18:43:09 CEST 2010
Final Memory: 40M/730M
------------------------------------------------------------------------
Comment 3 chrishhde 2010-08-13 17:09:25 UTC
Created attachment 101377 [details]
Netbeans Maven project
Comment 4 Jesse Glick 2010-12-02 13:29:38 UTC
Needs to be evaluated for feasibility.
Comment 5 Jesse Glick 2011-03-03 15:01:19 UTC
Not for 7.0.
Comment 6 Jesse Glick 2011-04-21 15:32:19 UTC
animal-sniffer-maven-plugin is more flexible and appropriate for projects that merely need to avoid using too-new Java Platform APIs in some or all of the code. Toolchains still useful if the project must build against a _newer_ Java API than the default (i.e. what the IDE is run on), e.g. JDK 7; and/or if a specific Java version is mandatory when running tests or running an app interactively; and/or if a special javac version is required.

Can already set a JDK for the project, but this uses NB-private metadata which is hard to share in a team and which will not be used for e.g. CI builds.

(Ideally API stubs from rt.jar would be a system-scope dependency you could version from Maven Central, and so would tools.jar for a maven-compiler-plugin dependency; would not help with running tests/app against a specific Java version, since the full JRE is platform-dependent.)
Comment 7 j.schneider123 2015-04-16 08:08:40 UTC
I think this one becomes even more important now that the current version of maven requires JDK 1.7 to be run, see http://blog.soebes.de/blog/2015/03/17/apache-maven-3-dot-3-1-features/ (officially linked as release notes) and https://jira.codehaus.org/browse/MNG-5780. 
We still have to build many of our projects against JDK 1.6. Currently, we set the project settings (Build->Compile) to JDK 1.6, but this won't work with Maven 3.3.1, because maven wouldn't run. Thus, we will have to upgrade our projects to use the toolchain-mechanism (as described in http://maven.apache.org/guides/mini/guide-using-toolchains.html). 
Doing so and setting the project's Java Platform to 1.7, the maven build runs fine using JDK 1.6 from the toolchains.xml. Anyway, NetBeans checks the sources against JDK 1.7 runtime libs. This means, for instance, that I can use java.nio.file.FileSystem(*) in the sources without NetBeans complaining about, but the maven build fails.

(*) This class has been introduced in 1.7.

Since it is probably not straight-forward to match toolchains.xml settings to NetBeans' Java Platforms, a simple solution would be to add an option "JAVA_HOME for Maven" to have this set independently from the projects Java Platform.
Comment 8 j.schneider123 2015-04-23 07:19:46 UTC
Regarding my previous comment: It is possible to to override JAVA_HOME for Maven by setting it in <NetBeansDir>/java/maven/bin/mvn.bat. Not very elegant, but it works.
Comment 9 terje7601 2015-08-25 13:44:00 UTC
I would already be very pleased with the following basic support for Maven toolchains:

- show the toolchains.xml which is in .m2 under "Project Files", just like settings.xml
- add "Create toolchains.xml" to the right-click popup-menu of "Project Files", which creates such a file in .m2

See http://blog.soebes.de/blog/2015/03/17/apache-maven-3-dot-3-1-features/ for more information on improved toolchains support in Maven 3.3.1