maven无法解决依赖关系

发布于 2024-12-10 03:14:49 字数 5025 浏览 1 评论 0原文

我有多模块 maven 项目。当我尝试构建站点时,例如在父项目上执行 maven site 时,它无法解析对其中一个模块的依赖关系。 但是,如果我只是编译(在父项目上的mvn cleancompile)或运行测试(在父项目上的mvn cleantest),则不存在依赖性问题。

什么可能导致这种行为?

UPD

Maven 版本

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 版本

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

错误消息

[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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

幼儿园老大 2024-12-17 03:14:49

我有同样的问题。我没有深入研究 Maven 的源代码。但这是我的观察。

假设您从未在本地存储库中 mvn install myproj-common ,也没有将其部署到任何远程存储库上。当您在父项目上运行 mvn clean site 时,会发生这样的事情:

  1. maven 确定 myproj-common 的顺序在之前
    myproj-client根据其依赖关系
  2. mvn clean site运行在myproj-common上。 myproj-common/target 中的所有先前结果均被删除,myproj-common/target/site 被删除
    生成的。 (请注意,执行此步骤后,myproj-common/target 中既不存在已编译的类,也不存在打包的 jar)
  3. mvn clean sitemyproj-client 上运行>。 Maven 首先检查
    该项目的依赖项,并尝试查找 myproj-common
    这些位置中的工件(类或 jar): (a) myproj-common/target (b) 本地存储库 (3) 远程存储库。
  4. mvn sitemyproj-client 上失败,因为它找不到 myproj-common 的工件

这解释了为什么 mvn cleancompilesite< /code> 和 mvn clean package site 有效。在 mvn sitemyproj-client 上运行之前,他们都会在其目标目录中准备好 myproj-common 工件。

mvn install 后跟 mvn site 也可以。

一个特殊的例外是,如果您在报告中放置类似 emma-maven-plugin 的内容,它会自动编译和检测类。在这种情况下,mvn clean site 始终有效。

我不知道为什么 Maven 在步骤 3 中试图找到 myproj-common 的 jar,它似乎与 mvn site 无关。在进入 maven-site-plugin 之前,异常很早就发生在 Maven 核心中。它看起来不像是 maven-site-plugin 的问题,而是所有 Maven 生命周期的常见行为(我相信除了 clean)。

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).

热风软妹 2024-12-17 03:14:49

我也面临着同样的问题,但对于 struts 和 paypal_base 依赖项,我通过执行以下操作来修复。

  1. 我检查了一下,发现 maven 存储库(.m2/repository....)中的相应文件夹中不存在 jar 文件。
  2. 我已经通过以下 mvn 命令安装了该 jar 文件

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

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

(-DFile 是 jar 文件在系统中的位置)

  1. 通过 Maven 重新构建项目。
  2. 我的项目构建成功。

你必须检查jar,并且使用上面的指令是jar不存在。
可能这会有所帮助。

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.

七禾 2024-12-17 03:14:49

这可能是站点插件无法访问反应器的问题,因此看不到项目工件在项目源中可用。 (这只是一个假设,可能得到 MSITE-302 的支持。)

先尝试运行mvn install,它将您的工件安装在本地存储库中,然后运行 ​​mvn site

有关反应器的更多信息,请尝试:

This might be an issue with the site plugin not having access to the reactor, and thus not seeing that the project artifact is available in your project sources. (This is merely a hypothesis, perhaps supported by MSITE-302.)

Try running first mvn install, which installs your artifacts in the local repository, and then running mvn site.

For more information on the reactor, try:

风苍溪 2024-12-17 03:14:49

呵呵,由于某种原因,在我对模块和父 pom 文件进行了一些更改后,问题就消失了。我不知道到底做了什么,但目前父项目上的 mvn site 工作正常。不幸的是我没有时间调查问题的根源是什么。但似乎将网站版本更改为 3.0 让我走上了正确的道路。我还可以通过以下方式执行站点(在修复之前):mvncompilesite,在这种情况下它可以找到依赖项。

Heh, for some reason, after I made some changes to module and parent pom files, problem vanished. I don't know exactly what was done, but currently mvn site on parent project is working normally. Unfortunately I have no time to investigate what is the roots of the problem. But it seems that changing site version to 3.0 put me on the right way. Also I could execute site (before it was fixed) in the following way mvn compile site, in this case it could find dependency.

沫尐诺 2024-12-17 03:14:49

看起来 maven 正在存储库中寻找 myproj-common:jar:0.0.1-SNAPSHOT 。

失败的原因可能是:
maven 无法访问存储库中的快照工件。

要启用快照工件:

请检查 pom.xml 中存储库部分下的 snapshots 标记。

<repository>
   <name>xyz</name>
   <id>repoid</id>
   <url>http://x.y.z</url>
   <releases>
       <enabled>true</enabled>
   </releases>
   <snapshots>
       <enabled>true</enabled>
   </snapshots>
</repository>

It looks like maven is looking for myproj-common:jar:0.0.1-SNAPSHOT in the repository.

The reason for failure could be:
maven is not able to access the snapshot artifacts in the repository.

To enable snapshot artifacts:

please check you pom.xml for snapshots tag under the repository section.

<repository>
   <name>xyz</name>
   <id>repoid</id>
   <url>http://x.y.z</url>
   <releases>
       <enabled>true</enabled>
   </releases>
   <snapshots>
       <enabled>true</enabled>
   </snapshots>
</repository>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文