Maven 3 Support in NetBeans IDE 7.0
Maven 3 Support in NetBeans IDE 7.0
Join the DZone community and get the full member experience.Join For Free
Java-based (JDBC) data connectivity to SaaS, NoSQL, and Big Data. Download Now.
The new Beta build of NetBeans IDE 7.0 offers complete support for Maven 3. (Apache Maven 3 release was announced in October, and focused on performance and usability improvements.) In this interview, NetBeans engineer Jesse Glick speaks about what new and existing Maven users should know about Maven integration in the NetBeans IDE.
What types of Maven projects can users work with in the NetBeans IDE?
Any valid Maven project can be at least opened in NetBeans. Java source roots can be opened with the usual code completion and similar features. General Maven capabilities such as dependency management and starting builds can be done from the IDE's UI (as well as directly in pom.xml, with various forms of code completion). The IDE also provides special support for certain "packagings"--Java EE applications, OSGi bundles, and NetBeans modules.
File > New Project also offers a Maven category so you can create new applications using Maven. Wizards are provided for some common project types such as Java EE 6 WARs. You can also pick from among the hundreds of "archetypes" (project templates) available to support popular technologies--everything from JIRA plugins to Scala/lift apps to Jini services. This is a great way to get your feet wet with a new framework.
With the release of Maven 3, what has changed about Maven integration in the NetBeans IDE?
Opening projects should be somewhat faster. Because the IDE is using the official Maven 3.0 code to parse your project, a lot of corner cases are now handled correctly that previously were not. And builds run from the IDE by default use the bundled Maven 3.0, which is generally faster than 2.x, and emits a number of warnings about configuration mistakes that ought to be fixed.
What other improvements in Maven support are included in NetBeans 7.0?
There have been numerous fixes and improvements to the Maven support in 7.0 beyond what was needed to integrate Maven 3.0. The NetBeans 7.0 New & Noteworthy page lists some of the more visible changes.
What is the level of compatibility for existing Maven 2 projects and with new Maven 3 projects?
Actual builds use the regular apache-maven-3.0/bin/mvn executable, so they should behave exactly like builds not involving the IDE. Maven 3.0 is generally compatible with projects created for Maven 2.x. There were a few listed incompatible changes which are typically easily fixed, and in many cases beneficial to fix even for 2.x users. From that list, the most common sources of problems I have encountered are:
- Projects which relied on profiles.xml now cannot move relevant profiles into pom.xml or settings.xml according to whether they are user-specific or sharable.
- "Legacy" repositories such as http://download.java.net/maven/1/ can no longer be used. Fortunately, most content is already in proper repositories.
- You need a new version of the Site plugin to work under Maven 3. The old version can still be used by Maven 2 builds if you define a profile.
- <parent> links need to use the actual version of the parent, and the actual <relativePath> if not ../pom.xml. Maven 2.x failed to warn about this kind of mistake.
As far as the IDE's parsing of Maven projects and display of their metadata (such as dependencies), full compatibility with the 3.0 command line is intended. Field testing should turn up any outstanding issues.
For those on the fence about Maven, who have had challenges with it in the past, or who use other build tools, how will their experience in the NetBeans IDE be different?
First, Maven differs from all other popular build tools in that the POM declares what the project contains and uses, rather than being a script in some sort of procedural language. (You can still insert bits of script using Ant, Groovy, etc. for unusual build tasks, but this is the exception rather than the rule.) This means that the IDE can effectively read the POM and know what to present to the user: where source roots are, what the dependencies are, what build steps ("plugins") are in use, how plugins are configured. IDE support for a build tool like Ant is mostly limited to running the script and offering basic syntax completion when editing it, so NetBeans defines proprietary metadata like the "nbproject" directory so it can open projects with some kind of structure. By contrast, NetBeans can at least open any existing Maven project, and important metadata is picked up directly from the POM. For example, the IDE's Java editor will automatically use the same classpath for showing live errors and hints as maven-compiler-plugin uses when actually building the project. IDE features to manipulate the POM, like dependency conflict resolution, work directly with Maven. There are plenty of littler features that make everyday development easier, too; for example, if your POM declares a popular license, File > New File will try to insert the appropriate copyright header.
Furthermore, NetBeans requires no "import" step to work with Maven projects the way some IDEs do: if you have the project on disk, the project - or any file in it - can be opened right away, with no need for any IDE-specific control files. You can also use Team > Create Build Job to ask the Hudson continuous integration server to begin building and testing your project with no configuration up front.
Second, Maven's repository and dependency system is very powerful and helps you maintain comprehensible, properly layered software. Libraries are cached in a repository, not checked in to source control. You can require that all components of your application depend on official releases of libraries declared in a single place - and this can even apply to libraries you wrote, so every component can be built in isolation. You do not need to check out a library project from version control just to get Javadoc and sources for debugging - but you can check it out and start making changes with a single step from the IDE. Most popular free/open-source Java libraries are already available in public Maven repositories for immediate use. There is no need to manually download and manage JARs and track down Javadoc, and standard Maven tools like maven-dependency-plugin can tell you if newer releases of any dependencies are available. maven-release-plugin provides a standard way to publish discrete releases of your own software, and repository managers like Nexus can index everything and enforce consistency rules.
NetBeans helps you work with repositories and dependencies with ease. Perhaps you found a neat code snippet on a developers' site using some API you had never heard of before. Paste it into the Java editor, and a hint will appear suggesting you add that library as a dependency, based on the class name appearing in a public repository index.
Browse the library under the Dependencies node beneath the project and open Javadoc, or pick a different version.
Right-click the project and select Show Dependency Graph to see if the library has any upstream dependencies you don't want, or which conflict with your preferred version.
Open the Maven Repository Browser window to see the universe of software in a searchable format (also integrated with the Quick Search toolbar); and open the metadata viewer for a library of interest so you can visit the project's bug tracker site, check out sources, or even find projects already using it.
Comparing the performance of Maven to other build tools may be missing the point, since the development models can be very different. Compiling and packing classes into a JAR runs the javac and jar commands regardless of the build tool, and the "Compile on Save" mode is available in NetBeans for Maven projects (including Java EE) just as for any other. What is more interesting is that the IDE's classpath scanning runs faster against a JAR than a source tree, and the up-to-date check is far faster for a JAR (i.e. a project-to-binary dependency rather than a project-to-project dependency). Most dependencies in a Maven project are against binary releases, so the IDE's Java editor does not need to constantly check for API changes in your classpath. This also works between projects you wrote, if you use "release" dependencies - making development of a very large Java application potentially much more efficient than when using one big Ant-based project or a tree of interdependent Ant projects. "Snapshot" dependencies can be used when you actually wish to work on parallel changes in two or more projects, in which case you pay the cost of the up-to-date checks just among those projects, and you can change your mind at any time just by switching dependency versions.
In parting, Maven 3.0 is a long-awaited release and I am proud to work on one of the first IDE integrations. I hope to see plenty of people trying it out in NetBeans 7.0 Beta and the nightly builds, and filing bugs early so the 7.0 release can be really polished in this area.
Opinions expressed by DZone contributors are their own.