
The Eclipse IDE is the most widely used IDE for Java development today. Eclipse has a huge amount of plugins (see http://www.eclipseplugincentral.com/) and an innumerable amount of organizations developing their own software on top of it. Quite simply, Eclipse is ubiquitous. The m2Eclipse project, provides support for Maven within the Eclipse IDE, and, in this chapter, we will explore the features it provides to help you use Maven with Eclipse.
The m2Eclipse plugins (http://m2eclipse.codehaus.org/) provide Maven integration for Eclipse. m2Eclipse also has hooks into the features of both the Subclipse plugin (http://subclipse.tigris.org/) and the Mylyn plugin (http://www.eclipse.org/mylyn/). The Subclipse plugin provides the m2eclipse plugin with the ability to interact with Subversion repositories, and the Mylyn plugin provides the m2eclipse plugin with the ability to interact with a task-focused interface that can keep track of development context. Just a few of the features m2eclipse provides include:
Creating and importing Maven projects
Dependency management and integration with the Eclipse classpath
Automatic dependency downloads and updates
Artifact Javadoc and source resolution
Creating projects with Maven Archetypes
Browsing and searching remote Maven repositories
POM management with automatic update to dependency list
Materializing a project from a Maven POM
Checking out a Maven project from several SCM repositories
Adapting nested multi-module Maven projects to the Eclipse IDE
Integration with Web Tools Project (WTP)
Integration with AspectJ Development Tools (AJDT)
Integration with Subclipse
Integration with Mylyn
Form-based POM Editor
Graphical Display of Dependency Graph
GUI Presentation of Dependency Tree and Resolved Dependencies
There are many more features in m2eclipse beyond the list above and this chapter introduces some of the more impressive features that are currently available. Let’s get started by installing the m2Eclipse plugin.
To install the m2Eclipse plugin, you will need to install some prerequisites. You will need to be running Eclipse 3.2 or higher, JDK 1.4 or higher, and you will also need to make sure that Eclipse is running on a JDK and not a JRE. Once you have Eclipse and a compatible JDK, you will need to install two Eclipse plugins: Subclipse and Mylyn.
You can install these prerequisites when you install m2eclipse, just add a new remote update site to Eclipse for each of the prerequisite components. To install these prerequisites, go to Help → → . Selecting this menu item will load the Install/Update dialog box. Choose the "Search for new features to install" option and click . You will then be presented with a list of "Update sites to visit". Click , and add a new update site for each new prerequisite. Add a new remote site for each plugin and then make sure that the remote site is selected. After you click , Eclipse will then ask you to select plugins components to install. Select the components you want to install and Eclipse will download, install, and configure your plugins.
Note that if you are using a recent build of Eclipse 3.4 (Ganymede) your plugin installation experience may be slightly different. In Ganymede, you will select → which will load the "Software Updates and Add-ons" dialog. In this dialog, choose the Available Software panel and click on which will load the simple "Add Site" dialog. Enter the URL of the update site you wish to add and click . In the "Software Updates and Add-ons" dialog, the available plugins from an update site will appear as soon as the site is added. You can then select the modules you want to install and click the button. Eclipse will then resolve all the dependencies for the selected plugins, and ask you to agree to the plugin license. After Eclipse installs new plugins, it will likely ask you for permission to restart.
To install Subclipse, use the Eclipse plugin update site listed below.
Subclipse 1.2: http://subclipse.tigris.org/update_1.2.x
For other versions of Subclipse, and for more information about the Subclipse plugin, please see the Subclipse project's web site at http://subclipse.tigris.org/.
To install JIRA integration with Mylyn, add the Mylyn extras Eclipse update URL, you'll want to do this if your organization uses Atlassian's JIRA for issue tracking. To install Mylyn use the following update sites:
Mylyn (Eclipse 3.3): http://download.eclipse.org/tools/mylyn/update/e3.3
Mylyn (Eclipse 3.4): http://download.eclipse.org/tools/mylyn/update/e3.4
Mylyn Extras (JIRA Support): http://download.eclipse.org/tools/mylyn/update/extras
For more information about the Mylyn project, see the Mylyn project's web site at http://www.eclipse.org/mylyn/.
If you are installing the 0.9.4 release of m2eclipse, you may also want to install both the Web Tools Platform (WTP) and the AspectJ Development Tools (AJDT). To install the AJDT use one of the following update URLs in Eclipse:
AJDT (Eclipse 3.3): http://download.eclipse.org/tools/ajdt/33/update
AJDT (Eclipse 3.4): http://download.eclipse.org/tools/ajdt/34/dev/update
For more information about the AJDT project, see the AJDT project's web site at http://www.eclipse.org/ajdt/.
To install the Web Tools Platform (WTP). Use one of the following update URLs in Eclipse, or just look for the Web Tools Project in the Discovery Site which should already be in your Eclipse remote update sites list.
For more information about the Web Tools Platform, see the Web Tools Platform project's web site at http://www.eclipse.org/webtools/.
Once you've installed the prerequisites, you can install the m2eclipse plugin from the following Eclipse update URL:
m2eclipse Plugin: http://m2eclipse.sonatype.org/update/
If you would like to install the latest snapshot development version of the plugin, you should use the update-dev URL instead of the previous URL:
m2eclipse Plugin (Development Snapshot): http://m2eclipse.sonatype.org/update-dev/
To install m2eclipse, just add a the appropriate update site for m2eclipse. Go to Help → → . Selecting this menu item will load the Install/Update dialog box. Choose the "Search for new features to install" option and click . You will then be presented with a list of "Update sites to visit". Click , and add a new update site for m2eclipse. Add a new remote site for m2eclipse and then make sure that the remote site is selected. After you click , Eclipse will then ask you to select plugins components to install. Select the components you want to install and Eclipse will download, install, and configure m2eclipse.
If you've installed the plugin successfully, you should see a Maven option in the list of preferences options when you go to Window → .
Before we begin to examine the features of m2eclipse, let’s first enable the Maven console. Open the Console View by going to → → . Then click on the little arrow on the right-hand side of the Open Console icon and select Maven Console as shown below:
Maven Console shows the Maven output that normally appears on the console when running Maven from the command line. It is useful to be able to see what Maven is doing and to work with Maven debug output to diagnose issues.
When using Maven, project creation takes place through the use of a Maven archetype. In Eclipse, project creation takes place via the new project wizard. The new project wizard inside of Eclipse offers a plethora of templates for creating new projects. The m2eclipse plugin improves upon this wizard to provide the following additional capabilities:
Checking out a Maven project from a SCM repository
Creating a Maven project using a Maven archetype
Creating a Maven POM file
As shown in Figure 14.2, “Creating a New Project with m2eclipse Wizards”, all three of these options are important to developers using Maven. Let’s take a look at each one.
m2eclipse provides the ability to check out a project directly from a SCM repository. Simply enter the SCM information for a project and it will check it out for you to a location of your choice as shown in Figure 14.3, “Checkout a New Project from Subversion”:
There are additional options in this dialog for specifying a particular revision by browsing the revisions in a Subversion repository or by simply entering the revision number manually. These features reuse of some of the features in the Subclipse plugin to interact with the Subversion repository. In addition to Subversion, the m2eclipse plugin also supports the following SCM providers:
Bazaar
Clearcase
CVS
git
hg
Perforce
Starteam
Subversion
Synergy
Visual SourceSafe
m2eclipse offers the ability to create a Maven project using a Maven Archetype. There are many Maven Archetypes provided in the list that comes with m2eclipse as shown in Figure 14.4, “Creating a New Project with a Maven Archetype”.
The list of archetypes in Figure 14.4, “Creating a New Project with a Maven Archetype” is a list generated by something called the Nexus Indexer. Nexus is a repository manager which is introduced in Chapter 16, Repository Manager. The Nexus indexer is a file which contains an index of the entire Maven repository, and m2eclipse uses it to list all of the available archetypes in the entire Maven repository. When this chapter was last updated, m2eclipse had approximately ninety archetypes in this Archetype dialog. Highlights of this list include:
Standard Maven Archetypes to create
Maven Plugins
Simple Web Applications
Simple Projects
New Maven Archetypes
Databinder
Archetypes (data-driven Wicket Applications) under
net.databinder
Apache Cocoon
Archetypes under org.apache.cocoon
Apache Directory
Server Archetypes under
org.apache.directory.server
Apache
Geronimo Archetypes under
org.apache.geronimo.buildsupport
Apache
MyFaces Archetypes under
org.apache.myfaces.buildtools
Apache
Tapestry Archetypes under
org.apache.tapestry
Apache Wicket
Archetypes under org.apache.wicket
AppFuse
Archetypes under org.appfuse.archetypes
Codehaus
Cargo Archetypes under
org.codehaus.cargo
Codehaus
Castor Archetypes under
org.codehaus.castor
Groovy-based
Maven Plugin Archetypes (deprecated)[4] under
org.codehaus.mojo.groovy
Jini Archetypes
Mule
Archetypes under org.mule.tools
Objectweb
Fractal Archetypes under
org.objectweb.fractal
Objectweb
Petals Archetypes under
org.objectweb.petals
ops4j Archetypes under org.ops4j
Parancoe under
org.parancoe
slf4j Archetypes under org.slf4j
Springframework
OSGI and Web Services Archetypes under
org.springframework
Trails
Framework Archetypes under
org.trailsframework
[4]And these were just the archetypes that were listed under the Nexus Indexer Catalog, if you switch Catalogs you'll see other archetypes. While your results may vary, the following additional archetypes were available in the Internal Catalog:
Atlassian
Confluence Plugin Archetype under
com.atlassian.maven.archetypes
Apache Struts
Archetypes under org.apache.struts
Apache Shale Archetypes under
org.apache.shale
A catalog is simply a reference to a repository index. You can manage the set of catalogs that the m2eclipse plugin knows about by clicking on the button next to the catalog drop down. If you have your own archetypes to add to this list, you can click on .
Once you choose an archetype, Maven will retrieve the appropriate artifact from the Maven repository and create a new Eclipse project with the selected archetype.
m2eclipse provides the ability to create a Maven module. Creating a Maven module is almost identical to creating a Maven project as it also creates a new Maven project using a Maven archetype. However, a Maven module is a subproject of another Maven project typically known as a parent project.
When creating a new Maven module you must select a parent project that already exists inside of Eclipse. Clicking the browse button displays a list of projects that already exist as shown in Figure 14.6, “Selecting a Parent Project for a New Maven Module”:
After selecting a parent project from the list, you are returned to the New Maven Module window and the Parent Project field is populated as shown in Figure 14.5, “Creating a New Maven Module”. Clicking will then display the standard list of archetypes from Section 14.5.2, “Creating a Maven Project from a Maven Archetype” so you can choose which one should be used to create the Maven module.
Another important feature m2eclipse offers is the ability to create a new Maven POM file. m2eclipse provides a wizard to easily create a new POM file inside of a project that is already in Eclipse. This POM creation wizard is shown in Figure 14.7, “Creating a New POM”:
Creating a new Maven POM is just a matter of selecting a project, entering the Group Id, Artifact Id, Version, choosing the Packaging type, and providing a Name into the fields provided and m2eclipse. Click the Next button to start adding dependencies.
As you can see in Figure 14.8, “Adding Dependencies to a New POM” here are no dependencies in the POM yet. Just click the button to query the central Maven repository for dependencies as shown next in Figure 14.9, “Querying the Central Repository for Dependencies”:
Querying for dependencies is as easy as entering the
groupId for the artifact you need. Figure 14.9, “Querying the Central Repository for Dependencies” shows a query for
org.apache.commons with commons-vfs
expanded to see which versions are available. Highlighting the
1.1-SNAPSHOT version of commons-vfs
and clicking takes you back to the dependency
selection where you can either query for more artifacts or just click
finish to create the POM. When you search for
dependencies, m2eclipse is making use of the same Nexus repository index
that is used in the Nexus Repository Manager from Chapter 16, Repository Manager.
Now that the you’ve seen the m2eclipse features for creating a new project, let’s look at a similar set of features for importing projects into Eclipse.
m2eclipse provides three options for importing a Maven project into Eclipse including:
Import an existing Maven project
Check out a Maven project from SCM
Materialize a Maven project
Figure 14.10, “Importing a Maven Project” shows the wizard for importing projects with the options for Maven provided by m2eclipse:
The dialog in Figure 14.10, “Importing a Maven Project” is displayed by using the File → command in Eclipse and then filtering the options by entering the word maven in the filter field. As noted above, there are three options available for importing a Maven project into Eclipse including: Maven Projects, Check out Maven Project from Subversion, and Materialize Maven Projects.
Importing a Maven project from Subversion is identical to the creation of a Maven project from Subversion as discussed in the previous section so discussion of it would be redundant. Let’s move on now to review the other two options for importing a Maven project into Eclipse.
m2eclipse can import a Maven project with an existing
pom.xml. By pointing at the directory where a Maven
project is located, m2eclipse detects all the Maven
POMs in the project and provides a hierarchical list
of them as shown in Figure 14.11, “Importing a Multi-module Maven Project”.
Figure 14.11, “Importing a Multi-module Maven Project” displays the view of the project being imported. Notice that all the POMs from the project are listed in a hierarchy. This allows you to easily select which POMs (and therefore which projects) that you want to be imported into Eclipse. Once you select the project you would like to import, m2eclipse will import and build the project(s) using Maven.
m2eclipse also offers the ability to "materialize" a Maven project. Materialization is similar to the process of checking out a Maven project from Subversion, but instead of manually entering the URL to the project’s Subversion repository, the Subversion URL is discovered from the project’s root POM file. You can use this feature to "materialize" projects from nothing more than a POM file if the POM file has the appropriate elements to specify the location of a source repository. Using this feature, you can browse the central Maven repository for projects, and materialize them into Eclipse projects. This comes in handy if your project depends on a third-party open source library, and you need to get your hands on the source code. Instead of tracking down the project web site and figuring out how to check it out of Subversion, just use the m2eclipse project to magically "materialize" the Eclipse project.
Figure 14.12, “Materializing a Maven Project” shows the wizard after choosing to materialize Maven projects:
Notice that the dialog box for Maven artifacts in Figure 14.12, “Materializing a Maven Project” is empty. This is because no projects have been added yet. In order to add a project, you must click the button on the right side and select a dependency to add from the central Maven repository. Figure 14.13, “Selecting Artifact to Materialize” shows how to add a project:
Upon entering a query, candidate dependencies will be located in the local Maven repository. After a few seconds of indexing the local Maven repository, the list of candidate dependencies appears. Select the dependency to add and click OK so that they are added to the list as shown in Figure 14.14, “Materializing Apache Camel”.
Upon adding a dependency, you have the option of telling the m2eclipse plugin to check out all projects for the artifact.
m2eclipse modified the and menus to allow you to run a Maven build within Eclipse. Figure 14.15, “Running an Eclipse build with Run As..” shows the menu for an m2eclipse project. From this menu you can run one of the more common lifecycle phases like clean, install, or package. You can also load up the Run configuration dialog window and configure a Maven build with parameters and more options.
If you need to configure a Maven build with more options, you can choose and create a new Maven build. Figure 14.16, “Configuring a Maven Build as a Run Configuration” shows the Run dialog for configuring a Maven build.
The Run configuration dialog allows you to specify multiple goals and profiles, it exposes options like "skip tests" and "update snapshots", and allows you to customize everything from the project to the JRE to the environment variable. You can use this dialog to support any custom Maven build that you wish to launch with m2eclipse.
The m2eclipse plugin also provides a set of features for working with Maven projects once they are inside of Eclipse. There are many features that ease the ability to use Maven in Eclipse so let’s dive right into them. In the previous section, I materialized a Maven project and selected a subproject from the Apache Camel project named camel-core. We’ll use that project to demonstrate these features.
By right-clicking on the camel-core project, and selecting the Maven menu item, you can see the available Maven features. Figure 14.17, “Available Maven Features” shows a screenshot of this:
Notice in Figure 14.17, “Available Maven Features” the available Maven features for the camel-core project, including:
Adding dependencies and plugins
Updating dependencies, snapshots and source folders
Creating a Maven module
Downloading the source
Opening Project URLs such as the Project Web Page, Issue Tracker, Source Control, and Continuous Integration tool.
Enabling /Disabling workspace resolution, nested Maven modules and dependency management
These features are also big time savers so let’s review them briefly.
Let’s say we’d like to add a dependency or a plugin to the
camel-core POM. For the sake of
demonstration, we're going to add commons-lang as a
dependency. (Please note that the functionality for adding a dependency
or a plugin is exactly the same so we’ll demonstrate it by adding a
dependency.)
m2eclipse offers two options for adding dependencies to a project.
The first option is by manually editing the POM file
to type in the XML to add the dependency. The
downside to manually editing the POM file to add a
dependency is that you must already know the information about the
artifact, or use the features discussed in the next section to manually
locate the artifact information in the repository indexes. The upside is
that after manually adding the dependency and saving the
POM, the project’s Maven Dependencies container will
be automatically updated to include the new dependency. Figure 14.18, “Manually Adding a Dependency to the Project's POM” shows how I added a dependency for
commons-lang to the camel-console
POM and the Maven Dependencies container was
automatically updated to included it:
Manually adding a dependency works well but requires more work than the second approach. Upon manually adding the dependency element to the POM, the Eclipse progress in the lower right-hand corner of the Eclipse workbench reflects the action as shown in Figure 14.19, “Updating Maven Dependencies”:
The second option for adding a dependency is much easier because
you don’t have to know any information about about the artifact other
than its groupId. Figure 14.20, “Searching for a Dependency” shows this functionality:
By simply entering a groupId into the query
field, m2eclipse queries the repository indexes and even shows a version
of the artifact that is currently in my local Maven repository. This
option is preferred because it is such a tremendous time saver. With
m2eclipse, you no longer need to hunt through the central Maven
repository for an artifact version.
m2eclipse makes it very easy to create a series of nested projects in a multi-module Maven project. If you have a parent project, and you want to add a module to the project, just right click on the project, go the Maven menu, and choose "New Maven Module Project". m2eclipse will walk you through the project creation process to create a new project, then it will update the parent project's POM to include the module reference. Before m2eclipse came along it was very difficult to use a hierarchy of Maven projects within Eclipse. With m2eclipse, the details of the underlying relationships between parent and child projects are integrated into the development environment.
If the central Maven repository contains a source artifact for a particular project, you can download the source from the repository and expose it to the Eclipse environment. When you are trying to debug a complex issue in Eclipse, nothing can be easier than being able to right click on a third-party dependency and drill into the code in the Eclipse debugger. Select this option, and m2eclipse will attempt to download the source artifact from the Maven repository. If it is unable to retrieve this source artifact, you should ask the maintainers of the project in question to upload the appropriate Maven source bundle to the central Maven repository.
A Maven POM contains some valuable URLs which a developer may need to consult. These are the project's web page, the URL for the source code repository, a URL for a continuous integration system like Hudson, and a URL for an issue tracker. If these URLs are present in a project's POM, m2eclipse will open these project pages in a browser.
You can configure a project to resolve dependencies from a
workspace. This has the effect of altering the way that Maven locates
dependency artifacts. If a project is configured to resolve dependencies
from the workspace, these artifacts do not need to be present in your
local repository. Assume that project-a and project-b are both in the
same Eclipse workspace, and that project-a depends on project-b. If
workspace resolution is disabled, the m2eclipse Maven build for
project-a will only succeed if
project-b's artifact is present in the local
repository. If workspace resolution is enabled, m2eclipse will resolve
the dependency via the eclipse workspace. In other words, when workspace
resolution is enabled, project's don't have to be installed in the local
repository to relate to one another.
You can also disable dependency management. This has the effect of telling m2eclipse to stop trying to manage your project's classpath, and it will remove the Maven Dependencies classpath container from your project. If you do this, you are essentially on your own when it comes to managing your project's classpath.
m2eclipse also provides some tools to make working with Maven repositories a bit easier. These tools provide functionality for:
Searching for Artifacts
Searching for Java classes
Indexing Maven repositories
m2eclipse adds a couple of items to the Eclipse Navigation menu that make searching for Maven Artifacts and Java classes easy work. Each option is available by clicking on the menu as shown in Figure 14.21, “Searching for Artifacts and Classes”:
Notice the available options in Figure 14.21, “Searching for Artifacts and Classes” under the Eclipse menu named and . The option allows you to search the Maven repository for a given POM as shown in Figure 14.22, “Searching for a POM”:
Upon selecting an artifact and clicking , the POM for that artifact is opened in Eclipse for browsing or editing. This is handy when you need to take a quick look at the POM for a given artifact.
The second m2eclipse option in the
menu is named . This
feature allows you to search for a Java class by name in a remote
repository. Upon opening this dialog, simply type ‘factorybean’ and
you’ll see many classes with the name FactoryBean
in them as shown in Figure 14.23, “Searching the Repository for a Class”:
This is a big time saving feature because it means that manually searching through artifacts in a Maven repository for a particular class is a thing of the past. If you need to use a specific class, just fire up Eclipse, go to the menu and search for the class. m2eclipse will show you the list of artifacts in which it appears.
The Maven Indexes View allows you to manually navigate to POMs in a remote repository and open them in Eclipse. To see this View, go to View → → , type the word "maven" into the search box and you should see a view named Maven Indexes as shown in Figure 14.24, “Show Maven Indexes View”:
Select this View and click . This will show the Maven Indexes View as shown in Figure 14.25, “Maven Indexes View”:
Additionally, Figure 14.26, “Locating a POM from the Indexes View” shows the Maven Indexes View after manually navigating to locate a POM:
After finding the apache-camel artifact,
double-clicking on it will open it up in Eclipse for browsing or
editing.
These features make working with remote repositories from inside of Eclipse so much easier and faster. After all the hours you may have spent doing these types of tasks by manually over the last few years - visiting repositories through a web browser, downloading artifacts and grepping through them for classes and POMs - you'll find that m2eclipse is a welcome change for the better.
The latest release of the m2eclipse plugin has a form-based
POM editor which allows you to edit every part of a
project's pom.xml with an easy-to-use
GUI interface. To open the POM
Editor, click on a project's pom.xml file. If you've
customized the editors for a pom.xml file, and the POM Editor is not the
default editor, you may need to right-click on the file and choose "Open
With... / Maven POM Editor". The POM Editor will then
display the Overview tab as shown in Figure 14.27, “Overview Tab of POM Editor for idiom-core”.
One common complaint about Maven is that it forces a developer to confront large and often overwhelming XML documents in a highly complex multi-module project build. While the authors of this book believe this is a small price to pay for the flexibility of a tool like Maven, the graphical POM editor is a tool that makes it possible for people to use Maven without ever having to know about the XML structure behind a Maven POM.
The project shown in Figure 14.27, “Overview Tab of POM Editor for idiom-core” is a project with an
artifactId of of idiom-core. You'll
notice that most of the fields in this idiom-core
project are blank. There is no groupId or
version and there is no SCM
information supplied in the POM editor. This is due to
the fact that idiom-core inherits most of this
information from a parent project named idiom. If we
open the pom.xml for the parent project in the
POM Editor we would see the Overview tab shown in Figure 14.28, “Overview Tab of POM Editor for idiom Parent Project”.
That “open folder” icon on the various list entries throughout the POM editor indicate that the corresponding entry is present in the Eclipse workspace and “jar” icon indicates artifacts which are referenced from the Maven repository. You can double-click on those entries in order to open its POM in the POM editor. This works for modules, dependencies, plugins and other elements that have corresponding Maven artifacts. Underlined labels in several POM editor sections represent hyperlinks which can be used to open the POM editor for corresponding Maven artifact.
In this parent POM, we see that the
groupId and version are defined and
that the parent POM supplies much of the information
which was missing in the idiom-core project. The
POM editor is going to show you the contents of the
POM that you are editing, and it will not show you any
of the inherited values. If you wanted to look at the
idiom-core project's effective POM
in the POM editor, you can use “Show Effective POM”
action from the tool-bar in the upper right-hand corner of the
POM editor, which shows a left bracket and an equals
sign on a page with a blue M. It will load the effective
POM for idiom-code in the
POM Editor as shown in Figure 14.29, “Effective POM for idiom-core”.
This effective view of the POM merges the
idiom-core POM with the ancestor
POMs (the parent, the grandparent, etc.), similarly to
“mvn help:effective-pom” command and displays the POM
editor with the effective values. Because the POM
editor is display a composite view of many different merged
POMs, this effective POM Editor is
read-only, and you will not be able to update any of the fields in this
effective POM view.
If you were looking at the POM editor for the idiom-core project as shown in Figure 14.27, “Overview Tab of POM Editor for idiom-core”, you can also navigate to the parent POM using, ”Open Parent POM” action from the POM editor tool-bar in the upper right-hand of the POM editor.
The POM editor shows a number of showing various
information from the POM. The final tab exposes the
pom.xml as an XML document. There
is a dependencies tab shown in Figure 14.30, “Dependencies Tab of the POM Editor” which exposes an
easy-to-use interface for adding and editing dependencies to your project,
as well as editing the dependencyManagement section of
the POM. This dependency management screen is also
integrated with the artifact searching facilities in the m2eclipse plugin.
You can use actions from the editor sections, as well as Ctrl-Space typing
assistance for the fields in “Dependency Details” section.
If you need to know more about one of the artifacts, you can use “Open Web Page” action from “Dependency Details” section tool-bar to check the project web page.
The build tab shown in Figure 14.31, “Build Tab of the POM Editor” provides access to the contents of the build element. From this tab you can customize source directories, add extensions, change the default goal name, and add resources directories.
We only showed a small subset of the POM editor. If you are interested in seeing the rest of the tabs, please download and install the m2eclipse plugin.
The latest release of m2eclipse contains a POM
editor which provides some dependency analysis tools. These tools promise
to change the way people maintain and monitor a project's transitive
dependencies. One of the main attractions to Maven is the fact that it
manages a project's dependencies. If you are writing an application which
depends on the Spring Framework's Hibernate3 integration, all you need to
do is depend on the spring-hibernate3 artifact from the
Central Maven Repository. Maven then reads this artifact's
POM and adds all of the necessary transitive
dependencies. While this is a great feature that attracts people to using
Maven in the first place, it can often become confusing with a project
starts to depend on tens of dependencies, each with tens of transitive
dependencies.
Problems start to happen when you depend on a project with a poorly
crafted POM which fails to flag dependencies as
optional, or when you start encountering conflicts between transitive
dependencies. If one of your requirements is to exclude a dependency like
commons-logging or the servlet-api,
or if you need to find out why a certain dependency is showing up under a
specific scope you will frequently need to invoke the
dependency:tree and
dependency:resolve goals from the command-line to track
down the offending transitive dependencies.
This is where the POM editor in m2eclipse comes in handy. If you open a project with many dependencies, you can open the Dependency Tree tab and see a two-column display of dependencies as shown in Figure 14.32, “Dependency Tree Tab of the POM Editor”. The left-side of the panel displays a tree of dependencies. The first level of the tree consists of direct dependencies from your project, and each subsequent level lists the dependencies of each dependency. The left-hand side is a great way to figure out how a specific dependency made its way into your project's resolved dependencies. The right-hand side of this panel displays the resolved dependencies. This is the list of effective dependencies after all conflicts and scopes have been applied, and it is the effective list of dependencies that your project will use for compilation, testing, and packaging.
The feature which makes the Dependency Tree tab so valuable is that
it can be used as an investigative tool to figure out how a specific
dependency made it into the list of resolved dependencies. Searching and
filtering functionality available in the editor makes it really easy to
search and browse trough the project dependencies. You can use “Search”
entry field from the editor tool-bar and “Sort” and “Filter” actions from
“Dependency Hierarchy” and “Resolved Dependencies” sections to navigate
trough dependencies. Figure 14.33, “Locating Dependencies in the Dependency Tree” shows what happens when
you click on commons-logging in the "Resolved Dependencies" list. When
filtering is enabled in “Dependencies Hierarchy” section, clicking on a
resolved dependency filters the hierarchy on the left-hand side of the
panel to show all of the node which contributed to the resolved
dependency. If you are trying to get rid of a resolved dependency, you can
use this tool to find out what dependencies (and what transitive
dependencies) are contributing the artifact to your resolved dependencies.
In other words, if you are trying to get rid of something like
commons-logging from your dependency set, the
Dependency Tree tab is the tool you will likely want to use.
m2eclipse also provides you with the ability to view your project's
dependencies as a graph. Figure 14.34, “Viewing the Dependencies of a Project as a Graph”
shows the dependencies of idiom-core. The top-most box
is the idiom-core project and the other dependencies
are shown below it. Direct dependencies are linked from the top box and
the transitive dependencies are linked from those. You can select a
specific node in the graph to highlight the linked dependencies, or you
can use the Search field at the top of the page to find matching
nodes.
Note that “open folder” icon on each graph node indicates that the corresponding artifact is present in the Eclipse workspace and “jar” icon indicates that the node's artifact is referenced from the Maven repository.
The graph presentation can be changed by right clicking in the editor. You can choose to show artifact ids, group ids, versions, scopes, or if you want to wrap node text or show icons. Figure 14.35, “Radial Layout of Dependency Graph” shows the same graph from Figure 14.34, “Viewing the Dependencies of a Project as a Graph” with a radial layout.