Bug 189496 - Support Maven toolchains and/or Animal Sniffer
Support Maven toolchains and/or Animal Sniffer
Status: NEW
Product: projects
Classification: Unclassified
Component: Maven
6.x
All All
: P3 (vote)
: TBD
Assigned To: Milos Kleint
issues@projects
: PLAN
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2010-08-13 16:59 UTC by chrishhde
Modified: 2012-06-19 16:15 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
:


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.)


By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo