Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven fails to resolve dependency

I have multi module maven project.When I try to build site, e.g. execute maven site on parent project it fails to resolve dependency to one of modules. But if I just compile (mvn clean compile on parent project) it or run tests (mvn clean test on parent project) there are no dependency problems.

What could cause such behaviour?

UPD

Maven version

Apache Maven 3.0.2 (r1056850; 2011-01-09 02:58:10+0200)
Java version: 1.6.0_26, vendor: Sun Microsystems Inc.
Java home: c:\Program Files\Java\jdk1.6.0_26\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

maven-site-plugin version

[DEBUG]   Included: org.apache.maven.plugins:maven-site-plugin:jar:2.0.1

Error message

[ERROR] Failed to execute goal on project myproj-client: Could not resolve dependencies for project mycompany.myproj:myproj-client:jar:0.0.1-SNAPSHOT: Could not find artifact mycompany.myproj:myproj-common:jar:0.0.1-SNAPSHOT -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project myproj-client: Could not resolve dependencies for project mycompany.myproj:myproj-client:jar:0.0.1-SNAPSHOT: Could not find artifact mycompany.myproj:myproj-common:jar:0.0.1-SNAPSHOT
    at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies(LifecycleDependencyResolver.java:190)
    at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.resolveProjectDependencies(LifecycleDependencyResolver.java:104)
    at org.apache.maven.lifecycle.internal.MojoExecutor.ensureDependenciesAreResolved(MojoExecutor.java:258)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:201)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.project.DependencyResolutionException: Could not resolve dependencies for project mycompany.myproj:myproj-client:jar:0.0.1-SNAPSHOT: Could not find artifact mycompany.myproj:myproj-common:jar:0.0.1-SNAPSHOT
    at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:156)
    at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies(LifecycleDependencyResolver.java:165)
    ... 22 more
Caused by: org.sonatype.aether.resolution.ArtifactResolutionException: Could not find artifact mycompany.myproj:myproj-common:jar:0.0.1-SNAPSHOT
    at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:526)
    at org.sonatype.aether.impl.internal.DefaultRepositorySystem.resolveArtifacts(DefaultRepositorySystem.java:304)
    at org.sonatype.aether.impl.internal.DefaultRepositorySystem.resolveDependencies(DefaultRepositorySystem.java:334)
    at org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:150)
    ... 23 more
Caused by: org.sonatype.aether.transfer.ArtifactNotFoundException: Could not find artifact mycompany.myproj:myproj-common:jar:0.0.1-SNAPSHOT
    at org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:517)
    ... 26 more
[ERROR] 
[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
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :myproj-client
like image 828
michael nesterenko Avatar asked Oct 14 '11 19:10

michael nesterenko


People also ask

How are Maven dependencies resolved?

Resolving Dependencies. 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.


2 Answers

I have the same problem. I didn't dig into Maven's source code too much. But here is my observation.

Supposed that you never mvn install myproj-common in your local repository, neither deployed it onto any remote repositories. When you run mvn clean site on the parent project, things happen like this:

  1. maven determines the order of myproj-common is before myproj-client according to their dependency relationship
  2. mvn clean site is run on myproj-common. All previous result in myproj-common/target are deleted and myproj-common/target/site is generated. (Note that after this step, neither compiled classes nor packaged jar exists in myproj-common/target)
  3. mvn clean site is run on myproj-client. Maven first checks the dependency of this project, and tries to find myproj-common's artifact (classes or jar) in these places: (a) myproj-common/target (b) local repository (3) remote repositories.
  4. mvn site fails on myproj-client, since it cannot find the artifact of myproj-common

This explains why mvn clean compile site and mvn clean package site works. They both would have prepared myproj-common artifacts in its target directory before mvn site runs on myproj-client.

And mvn install followed by mvn site works also.

A special exception is that if you put something like emma-maven-plugin in reporting, it will automatically compile and instrument classes. In this case, mvn clean site always works.

I am not sure why Maven tries to find myproj-common's jar in step 3, it seems to have nothing to do with mvn site. The exception happens quite early in maven core, before getting into maven-site-plugin. It looks not like a problem of maven-site-plugin but a common behavior of all maven lifecycles (except clean I believe).

like image 149
Achi Chen Avatar answered Sep 20 '22 13:09

Achi Chen


i was facing the same but for struts and paypal_base dependecies, i fixed by doing following.

  1. i checked, and found that jar files didn't exists in appropriate folder in maven repository(.m2/reposotory....).
  2. I have installed that jar files via following mvn command

    mvn install:install-file -Dfile=C:\Dependencies\paypal_base.jar \ -DgroupId=paypal -DartifactId=paypal_base -Dversion=0.1 \ -Dpackaging=jar

and

mvn install:install-file -Dfile=C:\Dependencies\struts.jar \
  -DgroupId=struts -DartifactId=struts -Dversion=0.1 \
  -Dpackaging=jar

(-DFile is the location of jar file in you system)

  1. Rebuild the project by Maven.
  2. My Project was successful build.

you must check the jar, and use above instruction is jar not exist. may be this will helpful.

like image 39
Garun Kumar Mishra Avatar answered Sep 21 '22 13:09

Garun Kumar Mishra