Red dependency in pom.xml

Hi!

I added

<dependency>
            <groupId>ch.ethz.ganymed</groupId>
            <artifactId>ganymed-ssh2</artifactId>
            <version>build210</version>
</dependency>

And it is red. What should I do to add this dependency in my project?

Thansk.

4 comments
Comment actions Permalink

That's usually a sign that IDEA is simply not finding the dependency in your local .m2 repository. Re-import the project (using the re import button maven-reimport.png on the maven tool window). IDEA should then go out and pull the dependency from maven central (or what ever additional repositories you have defined in your pom). If that does not fix it, just run the maven compile or test either from the command line or via the maven tool window.

0
Comment actions Permalink

Thanks a lot! It fixes the problem. But why some dependencies are added after typinig at pom.xml only and for other dependencies need doing maven compile, for example?

0
Comment actions Permalink

I'm not sure how familiar you are with how maven works in terms of its repositories...when a dependency is needed, maven looks in your local maven repository which is located in ~/.m2/repository by default, where ~ is your home directory. If the dependency does not exist in there (likely because you've never used it before in any project), maven finds it in an external repository and downloads it to your local repository. (By default maven only searches the maven central repository (see http://search.maven.org). But you can also configure other external repositories either in your maven pom or your maven settings.xml file.) So your local repository acts as a cache. This improves performance.

When you configure a dependency in your POM, IDEA looks for it in your local repository. If it is in your local repository (because you have used it before), all is good. However, if you have not used it before, IDEA can not verify that it is a valid dependency since it cannot find it. Sometimes you will only see the version number in red. This means you have used a different version of the dependency at some point, so IDEA can validate the groupID and artifactID, from your local repository, but cannot validate the version. Once you download that version (by running maven), the version will no longer be red.

You can ask IDEA to index repositories other than your local repository, like maven central. Open the Settings and go to the Maven node (it's under Build Tools in IDEA 14 if you are running the preview or the Release Candidate). Under the maven node, select the "Repository" node. At the top, in the "Indexed Maven Repositories" section, look for the maven central repository. If present, select it and click update. IDEA will index the repository (it takes a while). It will update in the background, so you can close the settings dialog. If the repository is not present, you can add it. The official Maven 2 repository is at http://repo.maven.apache.org/maven2 hosted in the US, or http://uk.maven.org/maven2 hosted in the UK. If you are working at a company that uses its own Nexus or Artifactory repository manager, you will want to index it rather than maven central.

I'm not entirely sure off-hand how indexing affects dependency resolving when editing your pom. I'm pretty sure if the artifact was present when you indexed, it will resolve (i,e, won't show red) in the pom even if it is not in your local repo. But I'm not 100% sure.

0
Comment actions Permalink

Thanks a lot for detailed answer!:)

0

Please sign in to leave a comment.