Maven 没有找到本地依赖
Maven does not find local dependency
TL;DR
Maven 在存储库 file://<homeDirectory>/.m2/repository/
中找不到 <importedGroupid>:<importedArtifactid>:jar:1.0
。该包裹实际上在 <homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/
我不认为我了解 Maven,但我能想到的两个潜在原因是:
- 它与
:
和 /
混淆(即 UNIX 风格的路径分隔符与 :
在 Maven 中的含义),或
- 如果
:
和/
实际上被解释为相同,它搜索的路径包括另一个子目录级别jar
,这在真正的目录结构中是不存在的。
详细说明
我试图在 Maven 中本地导入一个包(因为包没有在线部署)。 Whosebug 上的各种答案(例如,this, and this)在包含包的 jar 上推荐 运行 mvn install
(假设 jar 在 /usr/share/java
中,版本为 1.0,等等。等):
mvn install:install-file -Dfile=/usr/share/java/<importedArtifactid>-1.0-SNAPSHOT.jar -DgroupId=<importedGroupid> -DartifactId=<importedArtifactid> -Dversion=1.0 -Dpackaging=JAR -DgeneratePom=true
并在当前包的 pom.xml
中通过添加来定义它:
<repository>
<id>repository</id>
<url>file://${user.home}/.m2/repository/</url>
</repository>
mvn install
命令将包部署到 <homeDirectory>/.m2/repository/
。到目前为止,这工作正常:
<prompt> $ mvn install:install-file -Dfile=/usr/share/java/<importedArtifactid>-1.0-SNAPSHOT.jar -DgroupId=<importedGroupid> -DartifactId=<importedArtifactid> -Dversion=1.0 -Dpackaging=JAR -DgeneratePom=true
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building <currentDirectoryProject> 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ <currentDirectoryProjectArtifactid> ---
[INFO] Installing /usr/share/java/economicsl-1.0-SNAPSHOT.jar to <homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/<importedArtifactid>-1.0.JAR
[INFO] Installing /tmp/mvninstall256012398997457078.pom to <homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/<importedArtifactid>-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.489 s
[INFO] Finished at: 2017-05-11T19:11:12+01:00
[INFO] Final Memory: 9M/292M
[INFO] ------------------------------------------------------------------------
<prompt> $
包裹也出现在<homeDirectory>/.m2/repository/
<prompt> $ ls `<homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/`
<importedArtifactid>-1.0.JAR <importedArtifactid>-1.0.jar.lastUpdated <importedArtifactid>-1.0.pom _remote.repositories
<prompt> $
但是,构建尝试导入包的项目失败:
<prompt> $ mvn package -U
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building <currentDirectoryProject> 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: file://<homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/<importedArtifactid>-1.0.jar
Downloading: https://repo.maven.apache.org/maven2/<importedGroupid>/<importedArtifactid>/1.0/<importedArtifactid>-1.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.730 s
[INFO] Finished at: 2017-05-12T17:59:43+01:00
[INFO] Final Memory: 13M/292M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project <currentDirectoryProjectArtifactid>: Could not resolve dependencies for project <currentDirectoryProjectGroupid>:<currentDirectoryProjectArtifactid>:jar:1.0-SNAPSHOT: Could not find artifact <importedGroupid>:<importedArtifactid>:jar:1.0 in repository (file://<homeDirectory>/.m2/repository/) -> [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
<prompt> $
如果 /usr/share/java
中的 jar 的绝对路径在 pom.xml
中定义,项目将成功构建并警告不使用绝对路径,但执行失败,因为它没有找到这次又打包了。
Maven 版本为 Apache Maven 3.3.9。
占位符
<currentDirectoryProject>
应该导入其他包的项目。所有终端命令都从该项目的根目录执行(这是其 pom.xml
所在的位置)。
<currentDirectoryProjectArtifactid>
应该导入其他包的项目的 ArtifactID。
<currentDirectoryProjectGroupid>
应该导入其他包的项目的 GroupID。
<importedArtifactid>
要导入的项目的ArtifactID
<importedGroupid>
要导入的项目组ID
<homeDirectory>
用户的主目录,即 /home/<userName>
<prompt>
终端提示
您有一个大写的文件扩展名 "JAR",而 Maven 正在寻找小写的 "jar"。如果您的文件系统区分大小写,那么这很重要。
TL;DR
Maven 在存储库 file://<homeDirectory>/.m2/repository/
中找不到 <importedGroupid>:<importedArtifactid>:jar:1.0
。该包裹实际上在 <homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/
我不认为我了解 Maven,但我能想到的两个潜在原因是:
- 它与
:
和/
混淆(即 UNIX 风格的路径分隔符与:
在 Maven 中的含义),或 - 如果
:
和/
实际上被解释为相同,它搜索的路径包括另一个子目录级别jar
,这在真正的目录结构中是不存在的。
详细说明
我试图在 Maven 中本地导入一个包(因为包没有在线部署)。 Whosebug 上的各种答案(例如,this, and this)在包含包的 jar 上推荐 运行 mvn install
(假设 jar 在 /usr/share/java
中,版本为 1.0,等等。等):
mvn install:install-file -Dfile=/usr/share/java/<importedArtifactid>-1.0-SNAPSHOT.jar -DgroupId=<importedGroupid> -DartifactId=<importedArtifactid> -Dversion=1.0 -Dpackaging=JAR -DgeneratePom=true
并在当前包的 pom.xml
中通过添加来定义它:
<repository>
<id>repository</id>
<url>file://${user.home}/.m2/repository/</url>
</repository>
mvn install
命令将包部署到 <homeDirectory>/.m2/repository/
。到目前为止,这工作正常:
<prompt> $ mvn install:install-file -Dfile=/usr/share/java/<importedArtifactid>-1.0-SNAPSHOT.jar -DgroupId=<importedGroupid> -DartifactId=<importedArtifactid> -Dversion=1.0 -Dpackaging=JAR -DgeneratePom=true
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building <currentDirectoryProject> 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ <currentDirectoryProjectArtifactid> ---
[INFO] Installing /usr/share/java/economicsl-1.0-SNAPSHOT.jar to <homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/<importedArtifactid>-1.0.JAR
[INFO] Installing /tmp/mvninstall256012398997457078.pom to <homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/<importedArtifactid>-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.489 s
[INFO] Finished at: 2017-05-11T19:11:12+01:00
[INFO] Final Memory: 9M/292M
[INFO] ------------------------------------------------------------------------
<prompt> $
包裹也出现在<homeDirectory>/.m2/repository/
<prompt> $ ls `<homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/`
<importedArtifactid>-1.0.JAR <importedArtifactid>-1.0.jar.lastUpdated <importedArtifactid>-1.0.pom _remote.repositories
<prompt> $
但是,构建尝试导入包的项目失败:
<prompt> $ mvn package -U
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building <currentDirectoryProject> 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: file://<homeDirectory>/.m2/repository/<importedGroupid>/<importedArtifactid>/1.0/<importedArtifactid>-1.0.jar
Downloading: https://repo.maven.apache.org/maven2/<importedGroupid>/<importedArtifactid>/1.0/<importedArtifactid>-1.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.730 s
[INFO] Finished at: 2017-05-12T17:59:43+01:00
[INFO] Final Memory: 13M/292M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project <currentDirectoryProjectArtifactid>: Could not resolve dependencies for project <currentDirectoryProjectGroupid>:<currentDirectoryProjectArtifactid>:jar:1.0-SNAPSHOT: Could not find artifact <importedGroupid>:<importedArtifactid>:jar:1.0 in repository (file://<homeDirectory>/.m2/repository/) -> [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
<prompt> $
如果 /usr/share/java
中的 jar 的绝对路径在 pom.xml
中定义,项目将成功构建并警告不使用绝对路径,但执行失败,因为它没有找到这次又打包了。
Maven 版本为 Apache Maven 3.3.9。
占位符
<currentDirectoryProject>
应该导入其他包的项目。所有终端命令都从该项目的根目录执行(这是其pom.xml
所在的位置)。<currentDirectoryProjectArtifactid>
应该导入其他包的项目的 ArtifactID。<currentDirectoryProjectGroupid>
应该导入其他包的项目的 GroupID。<importedArtifactid>
要导入的项目的ArtifactID<importedGroupid>
要导入的项目组ID<homeDirectory>
用户的主目录,即/home/<userName>
<prompt>
终端提示
您有一个大写的文件扩展名 "JAR",而 Maven 正在寻找小写的 "jar"。如果您的文件系统区分大小写,那么这很重要。