gpt4 book ai didi

java - maven 无法解决依赖关系

转载 作者:搜寻专家 更新时间:2023-10-30 21:22:26 24 4
gpt4 key购买 nike

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

什么会导致这种行为?

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

最佳答案

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

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

  1. maven 确定 myproj-common 的顺序在之前myproj-client 根据它们的依赖关系
  2. mvn clean sitemyproj-common 上运行。 myproj-common/target 中的所有先前结果都被删除并且 myproj-common/target/site 是产生。 (注意这一步之后,myproj-common/target中既没有编译类也没有打包jar)
  3. mvn clean sitemyproj-client 上运行。 Maven 首先检查此项目的依赖项,并尝试找到 myproj-common 的这些地方的 Artifact (类或 jar):(a) myproj-common/target (b) 本地存储库 (3) 远程存储库。
  4. mvn sitemyproj-client 上失败,因为它找不到 myproj-common
  5. 的 Artifact

这解释了为什么 mvn clean compile sitemvn clean package site 有效。在 myproj-client 上运行 mvn site 之前,他们都已经在其目标目录中准备了 myproj-common Artifact 。

mvn install 后接 mvn site 也可以。

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

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

关于java - maven 无法解决依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7772556/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com