7

I added a Maven dependency to my project and my project compiles locally, while it doesn't compile on server. It can not resolve the newly added dependency.

This is my pom.xml file:

    <repositories>
        <repository>
            <id>rep</id>
            <name>Repository</name>
            <url>http://artifacts.com/rep</url>
            <releases>
               <enabled>true</enabled>
               <updatePolicy>always</updatePolicy>
            </releases>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>com.project.rest</groupId>
            <artifactId>common</artifactId>
            <version>2.0.5</version>
        </dependency>
    </dependencies>

And this my console output with an error:

 Downloading: http://artifacts.com/rep/com/project/rest/common/2.0.5/common-2.0.5.pom
    [WARNING] The POM for com.project.rest:common:jar:2.0.5 is missing, no dependency information available

    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 6.154s
    [INFO] Finished at: Tue Feb 03 06:58:35 BRT 2015
    [INFO] Final Memory: 9M/152M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal on project server: Could not resolve dependencies for project org.server:
    server:jar:2.5.1-SNAPSHOT: The following artifacts could not be resolved: com.project.rest:common:jar:2.0.5:
    Could not find artifact com.project.rest:common:jar:2.0.5 in rep (http://artifacts.com/rep) -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

(I hid all real URLs and package.)

What could be the problem?

Sabina Orazem
  • 477
  • 4
  • 12
lapots
  • 12,553
  • 32
  • 121
  • 242

6 Answers6

2

The first line "Downloading:..." only says that maven tries to download the artifact. It is no statement about success. If maven is successful you will get another line starting with "Downloaded: ..."

So in your case maven was not able to download the file. Check the logged url in your browser if it does exist and if it is protected.

BTW <updatePolicy>always</updatePolicy> is quite uncommon for release repos, because releases should not change any more.

Horst Krause
  • 636
  • 7
  • 22
2

Make sure your repository is configured properly. Try to search, in your repo, for com.project.rest:common of version 2.0.5.

Is this your own project? some jar that you have built? are you sure you deployed it to your repo? if it is not in your repo, try to search for it in your local repo (usually .m2/repository/com/project...)

OhadR
  • 8,276
  • 3
  • 47
  • 53
  • Yes. It contains jars. "common-2.0.5.jar" exists in `http://artifacts.com/rep/com.project.rest/common/2.0.5/common-2.0.5.jar` – lapots Feb 03 '15 at 11:36
  • and the pom exists there as well? – OhadR Feb 03 '15 at 11:45
  • so this is not a mven project. this is why maven cannot find its pom.xml :) the missing pom - is it your project? something that you wrote? – OhadR Feb 03 '15 at 13:13
2

DependencyResolutionException

(source: Maven Confluence)

This error generally occurs when Maven could not download dependencies. Possible causes for this error are:

  1. The POM misses the declaration of the <repository> which hosts the artifact.
  2. The repository you have configured requires authentication and Maven failed to provide the correct credentials to the server. In this case, make sure your ${user.home}/.m2/settings.xml contains a <server> declaration whose <id> matches the <id> of the remote repository to use. See the Maven Settings Reference for more details.
  3. The remote repository in question uses SSL and the JVM running Maven does not trust the certificate of the server.
  4. There is a general network problem that prevents Maven from accessing any remote repository, e.g. a missing proxy configuration.
  5. You have configured Maven to perform strict checksum validation and the files to download got corrupted.
  6. Maven failed to save the files to your local repository, see LocalRepositoryNotAccessibleException for more details.
  7. In Maven 3 if you just had a failed download and have fixed it (e.g. by uploading the jar to a repository) it will cache the failure. To force a refresh add -U to the command line.

In case of a general network-related problem, you could also consult the following articles:

naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
0

The project you mentioned doesn't contains POM i.e. it is not a MAVEN project. The .m2(look this at c drive or where you have installed) repository contains all the dependencies folders look there whether it contains the required project or not i.e. com.project.rest.

Ankit Khare
  • 1,345
  • 11
  • 30
  • Hm hm...So I have to load jars plainly? – lapots Feb 03 '15 at 11:15
  • Search in your .m2 repository which version of the project is their. And give that version in your POM. – Ankit Khare Feb 03 '15 at 11:25
  • then your repo doesn't contain any version of this project, their must be some error, can you provide more info regarding this project? – Ankit Khare Feb 03 '15 at 11:51
  • well in the folder it contains `ivy-2.0.5.xml` and several jars - `jar, jar.md5, jar.sha1`. Well to be precise this repo is usually used with gradle and not maven. The whole project I do not myself - I know only `jar` location – lapots Feb 03 '15 at 12:03
  • Their must be a xml file which contains the details of version open it and see which version are their. – Ankit Khare Feb 03 '15 at 12:07
  • well `ivy.xml` contains information regarding organization, module and revision. but well...this repository is used for `gradle` usually – lapots Feb 03 '15 at 12:20
0

Like suggested by console output, you can check the Maven Wiki page (http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException) for more information on where the problem might lay.

Given the information you provided. I would guess we are looking at the point one issue: The POM misses the declaration of the which hosts the artifact.

Maven repositories are of three types: local, central and remote.

In your case, your local repository contains the project specific artifacts, but the central repository doesn't.

  1. Local repository is on your local machine. When you run a Maven build, Maven automatically downloads all the dependency jars into the local repository.
  2. Central repository is web repository provided by a community and it contains a number of commonly used libraries, found here https://repo1.maven.org/maven2/.
  3. Remote repository is developer's own custom repository containing required libraries or other project jars. Developer defines these repositories in POM file using tags.

I would suggest the following:

  • check your repository tag, if the repository is correct
  • check if the repository contains the artifacts specified in your dependency tag
Sabina Orazem
  • 477
  • 4
  • 12
0

If you are using IntelliJ IDE (Jetbrains) and code is correct then

Check the TOGGLE OFFLINE MODE button. If we enable offline mode, then IDE do not let maven download a dependency and it cannot found the library that causes error.

So make sure your project is build in ONLINE mode.

Vijay
  • 1,163
  • 8
  • 22