Maven多仓库配置异常:父构件无法从指定仓库拉取
Maven父POM解析失败:依赖仅存在于未激活的Profile仓库
问题核心
父构件org.cmsk.cdparent:oparent:2.1.0仅存在于cmsk-public Profile对应的仓库中,但执行mvn clean deploy或mvn clean install时,Maven仅尝试从jfrog Profile的仓库拉取该构件,导致解析失败并返回401错误。
相关配置
pom.xml核心内容
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>org.cmsk.vod</groupId> <artifactId>vod-parent</artifactId> <version>8.0.2-SNAPSHOT</version> <packaging>pom</packaging> <name>vod-parent</name> <parent> <groupId>org.cmsk.cdparent</groupId> <artifactId>oparent</artifactId> <version>2.1.0</version> <relativePath/> </parent> <modules> <module>.....</module> <module>.....</module> <module>.....</module> <module>......</module> </modules> . . . . </project>
settings.xml中Profile配置
<profiles> <profile> <id>jfrog</id> <!-- Enable snapshots for the built in central repo to direct --> <!-- all requests to nexus via the mirror --> <repositories> <repository> <id>public</id> <url>URL1</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> <repository> <id>releases</id> <url>URL2</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> <repository> <id>snapshots</id> <url>URL3</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> <repository> <id>cmsk</id> <url>URL4</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>central</id> <url>URL1</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </pluginRepository> </pluginRepositories> </profile> <profile> <id>cmsk-public</id> <repositories> <repository> <id>cmsk-public</id> <name>cmsk-public</name> <url>URL5</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> </repositories> </profile> </profiles>
错误日志
[INFO] Error stacktraces are turned on. [INFO] Scanning for projects... Downloading from public: URL1/org/cmsk/cdparent/oparent/2.1.0/oparent-2.1.0.pom Downloading from releases: URL2/org/cmsk/cdparent/oparent/2.1.0/oparent-2.1.0.pom Downloading from snapshots: URL3/org/cmsk/cdparent/oparent/2.1.0/oparent-2.1.0.pom Downloading from cmsk: URL4/org/cmsk/cdparent/oparent/2.1.0/oparent-2.1.0.pom [ERROR] [ERROR] Some problems were encountered while processing the POMs: [FATAL] Non-resolvable parent POM for org.cmsk.vod:vod-parent:8.0.2-SNAPSHOT: The following artifacts could not be resolved: org.cmsk.cdparent:oparent:pom:2.1.0 (absent): Could not transfer artifact org.cmsk.cdparent:oparent:pom:2.1.0 from/to public (URL1): status code: 401, reason phrase: (401) and 'parent.relativePath' points at wrong local POM @ line 9, column 13 @ [ERROR] The build could not read 1 project -> [Help 1] org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs: [FATAL] Non-resolvable parent POM for org.cmsk.vod:vod-parent:8.0.2-SNAPSHOT: The following artifacts could not be resolved: org.cmsk.cdparent:oparent:pom:2.1.0 (absent): Could not transfer artifact org.cmsk.cdparent:oparent:pom:2.1.0 from/to public (URL1): status code: 401, reason phrase: (401) and 'parent.relativePath' points at wrong local POM @ line 9, column 13
解决思路
同时激活两个Profile:Maven默认可能仅激活了
jfrogProfile,需要同时启用cmsk-public,让Maven合并两个Profile的仓库列表。可以通过命令行参数指定:mvn clean deploy -P jfrog,cmsk-public或者在
settings.xml中添加activeProfiles配置,永久激活两个Profile:<activeProfiles> <activeProfile>jfrog</activeProfile> <activeProfile>cmsk-public</activeProfile> </activeProfiles>合并Profile仓库配置:将
cmsk-publicProfile中的仓库配置合并到jfrogProfile中,这样激活jfrog时就自动包含了父构件所在的仓库,无需额外激活其他Profile。修改后的jfrogProfile仓库配置如下:<profile> <id>jfrog</id> <repositories> <!-- 原有仓库配置 --> <repository> <id>public</id> <url>URL1</url> <!-- 省略其他配置 --> </repository> <!-- 添加cmsk-public仓库 --> <repository> <id>cmsk-public</id> <name>cmsk-public</name> <url>URL5</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> </repositories> <!-- 插件仓库配置省略 --> </profile>临时在pom.xml中添加仓库:不推荐长期使用,但可以临时在项目的
pom.xml中添加cmsk-public仓库,确保父构件能被解析。添加内容如下:<repositories> <repository> <id>cmsk-public</id> <name>cmsk-public</name> <url>URL5</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> </snapshots> </repository> </repositories>检查镜像配置:如果
settings.xml中有镜像(mirrors)配置,确认是否有镜像覆盖了cmsk-public仓库的请求,导致Maven无法正确访问该仓库。
内容的提问来源于stack exchange,提问作者hell_storm2004
相关产品推荐
相关产品推荐

