maven 无法解决依赖关系问题

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

什么可能导致这种行为?

断续器

马文版

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] 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

答案 1

我有同样的问题。我没有过多地挖掘Maven的源代码。但这是我的观察。

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

  1. maven根据myproj-common的依赖关系确定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的工件(类或jar):(a)myproj-common/target(b)本地存储库(3)远程存储库。
  4. mvn sitemyproj-client 上失败,因为它找不到 myproj-common 的工件

这就解释了为什么和有效。在myproj客户端上运行之前,他们都会在其目标目录中准备myproj-common工件。mvn clean compile sitemvn clean package sitemvn site

其次是作品。mvn installmvn site

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

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


答案 2

我面对的是相同的,但对于支柱和PayPal_base依赖,我通过执行以下操作进行修复。

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

    mvn install:install-file -Dfile=C:\Dependencies\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不存在。也许这会有帮助。


推荐