gpt4 book ai didi

java - 即使在构建过程中在 Maven 本地存储库中创建了依赖组件的 jar,也会查找自定义远程存储库

转载 作者:行者123 更新时间:2023-12-02 09:39:20 24 4
gpt4 key购买 nike

我的 Maven 项目中有一个依赖项和一个依赖组件。

我已经使用clean install成功创建了依赖项目的jar -

[INFO] Installing /Users/sandeepan.nath/Desktop/codebase/path/to/component1/target/project-component-1-1.0.1-SNAPSHOT.jar to /Users/sandeepan.nath/.m2/repository/path/to/project-component-1/1.0.1-SNAPSHOT/project-component-1-1.0.1-SNAPSHOT.jar
[DEBUG] Writing tracking file /Users/sandeepan.nath/.m2/repository/path/to/project-component-1/1.0.1-SNAPSHOT/_remote.repositories
[INFO] Installing /Users/sandeepan.nath/Desktop/codebase/path/to/project-component-1/pom.xml to /Users/sandeepan.nath/.m2/repository/com/path/to/project-component-1/1.0.1-SNAPSHOT/project-component-1-1.0.1-SNAPSHOT.pom
[DEBUG] Writing tracking file /Users/sandeepan.nath/.m2/repository/path/to-project-component-1/1.0.1-SNAPSHOT/_remote.repositories
[DEBUG] Installing com.project:project-component-1:1.0.1-SNAPSHOT/maven-metadata.xml to /Users/sandeepan.nath/.m2/repository/path/to/project-component-1/1.0.1-SNAPSHOT/maven-metadata-local.xml
[DEBUG] Installing com.project:project-component-1/maven-metadata.xml to /Users/sandeepan.nath/.m2/repository/path/to/project-component-1/maven-metadata-local.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------

我还确认存储库存在于路径 -/Users/sandeepan.nath/.m2/repository/path/to/project-component-1/1.0.1-SNAPSHOT/

以下是生成的文件的权限-

SandeepanNath:1.0.1-SNAPSHOT sandeepan.nath$ ls -l
total 312
-rw-r--r-- 1 sandeepan.nath IDC\Domain Users 264 Jul 26 21:24 _remote.repositories
-rw-r--r-- 1 sandeepan.nath IDC\Domain Users 107794 Jul 26 21:24 project-component-1-1.0.1-SNAPSHOT.jar
-rw-r--r-- 1 sandeepan.nath IDC\Domain Users 428 Jul 26 19:19 project-component-1-1.0.1-SNAPSHOT.jar.lastUpdated
-rw-r--r-- 1 sandeepan.nath IDC\Domain Users 6733 Jul 26 21:01 project-component-1-1.0.1-SNAPSHOT.pom
-rw-r--r-- 1 sandeepan.nath IDC\Domain Users 428 Jul 26 19:19 project-component-1-1.0.1-SNAPSHOT.pom.lastUpdated
-rw-r--r-- 1 sandeepan.nath IDC\Domain Users 739 Jul 26 21:24 maven-metadata-local.xml
-rw-r--r-- 1 sandeepan.nath IDC\Domain Users 342 Jul 26 21:26 resolver-status.properties

注意 - 我不确定为什么该 jar 不存在于组件的目标目录中。 根据我的理解,依赖组件的 jar 将首先在组件的目标目录中查找项目,然后在maven本地仓库中,最后在远程仓库中。

现在,当我尝试在依赖组件上运行全新安装时,我收到以下错误 -

依赖项目是否尝试引用依赖项目的 .m2 或/target 文件夹?

[ERROR] Failed to execute goal on project project-component-2: Could not resolve dependencies for project project-component-2:jar:1.0.1-SNAPSHOT: Failed to collect dependencies at project-component-1:jar:1.0.1-SNAPSHOT: Failed to read artifact descriptor for project-component-1:jar:1.0.1-SNAPSHOT: Could not find artifact project:path:pom:1.0.1-SNAPSHOT in nexus (https://project-repository.com/repository/maven-public/) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project project-component-2: Could not resolve dependencies for project project-component-2:jar:1.0.1-SNAPSHOT: Failed to collect dependencies at project-component-1:jar:1.0.1-SNAPSHOT
at org.apache.maven.lifecycle.internal.LifecycleDependencyResolver.getDependencies(LifecycleDependencyResolver.java:269)

此存储库 URL 在 maven settings.xml 中定义为 -

<localRepository>/Users/sandeepan.nath/.m2/repository</localRepository>
<servers>

<server>
<id>repo-id</id>
<username>cred</username>
<password>cred</password>
</server>
<server>
<id>repo-id-2</id>
<username>cred</username>
<password>cred</password>
</server>
<server>
<id>repo-id-3</id>
<username>cred</username>
<password>cred</password>
</server>
<server>
<id>repo-id-4</id>
<username>cred</username>
<password>cred</password>
</server>
<server>
<id>repo-id-5</id>
<username>cred</username>
<password>cred</password>
</server>
</servers>


<mirrors>
<mirror>
<id>repo</id>
<mirrorOf>repo-id-5</mirrorOf>
<url>https://project-repository.com/repository/maven-snapshots</url>
</mirror>
<mirror>
<id>repo-id-4</id>
<mirrorOf>nexus-snapshots-prepaid</mirrorOf>
<url>https://project-repository.com/repository/maven-snapshots</url>
</mirror>
<mirror>
<id>repo-id-1</id>
<mirrorOf>*</mirrorOf>
<url>https://project-repository.com/repository/maven-public/</url>
</mirror>
</mirrors>

注意 - 如果我在替换项目的实际名称/路径时犯了任何错误,请忽略。

更新

Maven 版本 3.3.9。Java 版本 1.8。

更新2

这是依赖组件 pom 中的一些部分(可能相关) -

<parent>
<groupId>com.project</groupId>
<artifactId>project-base</artifactId>
<version>1.0.1-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>

<artifactId>project-component-1</artifactId>
<packaging>jar</packaging>

<name>project-component-1</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.project.dependencies</groupId>
<artifactId>dependency-of-project-component-1</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>

更新3

我之前尝试过更新快照配置 -

enter image description here

我也尝试过使用mvn clean install -U,但结果相同。

更新4

根据此评论 -

I guess you have a problem in your local repository. Delete the directory /Users/sandeepan.nath/.m2/repository/path/to/project-component-1/1.0.1-SNAPSHOT/ and then build the first artifact again.

也尝试过,但仍然是同样的错误。删除 1.0.1-SNAPSHOT 目录并构建第一个 Artifact 后,该目录再次出现,仅包含 .jar 文件。我想,早些时候 .lastUpdated 文件也在那里。但是,尝试构建第二个 Artifact 时的错误仍然相同。

最佳答案

您需要使用 -U 调用clean install,因为本地存储库中有 lastUpdated 文件。这些缓存表明 Artifact 不存在。

关于java - 即使在构建过程中在 Maven 本地存储库中创建了依赖组件的 jar,也会查找自定义远程存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57223753/

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