John Humphreys
John Humphreys

Reputation: 39354

Maven integration with IDEs

I thought I understood Maven as I've worked on a few projects using it, but I seem to be having trouble creating my own project with it, so can someone correct me wherever I may be wrong?

Assuming I create a new Maven project (we'll say I did it through Eclipse or IntelliJ):

  1. If I add a dependency to my POM file, assuming I add a public repository where that dependency can be found, shouldn't the IDE download the specified JAR and make it so that it is recognized when I use it in my code? Currently, my projects do not recognize any classes that should be found in JARs via my POM dependencies.
  2. Assuming #1 does work, how can I determine via maven which transient dependencies I have? For example, I'm using classes from Pentaho Data Integration, and some of the plugins for it reference things like org.mozilla.javascript.*. Could maven automatically tell me that without me having to run the code, see it fail, and manually fix the dependency? There will be hundreds of those instances here, so manual fixing really isn't viable.

Upvotes: 0

Views: 145

Answers (2)

user626607
user626607

Reputation:

Question 1: Adding a dependency

In Eclipse, depending on how you created the project, you should be able to add dependencies that are automatically recognized using the maven context menu.

Note that you should have created the project using the eclipse maven plugin so that it has maven nature.

To add dependencies/plugins from a remote repository, you can search in the resulting UI for a dependency if you know the artifactId or groupId. The plugin will pull up the deps whether the repo url is specified in the pom.xml or not.

After adding a dependency to the POM, the IDE will start downloading it and all transient dependencies as soon as you save the file.

If something goes wrong, you can try to "Update Project" from the context menu.

Question 2: Determining transitive dependencies

Transient dependencies are visible in the "Dependency Hierarchy" tab of the POM editor.

I usually default to the command line because it allows much more flexibility and functionality when tracking the dependency graph.

I am sorry but I have not worked with IntelliJ

Upvotes: 2

Vic
Vic

Reputation: 22051

Here are my IntelliJ two cents:

1 - Adding a dependency in pom.xml of your project

Should indeed download the depended jar(s). You may need to approve "Import Changes" dialog if it pops in, or enable auto import.

2 - Seeing transitive dependencies

It can be achieved via Maven Dependencies Diagram - unfortunately only in IntelliJ Ultimate edition. You can use Maven Dependencies Plugin to see the dependencies tree in your favorite CLI.

Upvotes: 3

Related Questions