apache - 无法传输工件:未解释 settings.xml 属性
问题描述
我正在尝试在一个项目上构建一个 gitlab-ci:
- 位于我们的 nexus 存储库中的父 pom(不是父目录)
- 使用settings.xml 中设置
maven.repo.url
的属性
当将条目替换为硬编码的 url时,这适用于pom.xml ,例如. 但是,当尝试使用settings.xml 中设置的属性时,构建错误会抱怨repositories.repository.url
${maven.repo.url}/public
http://localhost:8081/nexus/content/repositories/public
无法将工件 mygroup:myparent:1.0-SNAPSHOT 从/向 myrepo (${maven.repo.url}/public) 传输。
.gitlab-ci.yml
image: maven:3.6.1-jdk-8-alpine
variables:
MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
cache:
paths:
- .m2/repository/
build:
stage: build
script:
- mvn $MAVEN_CLI_OPTS clean compile
test:
stage: test
script:
- mvn $MAVEN_CLI_OPTS test
deploy:
stage: deploy
script:
- mvn $MAVEN_CLI_OPTS deploy
only:
- master
.m2/settings.xml(注意:我已经MAVEN_REPO_URL
在我的 GitLab 组变量中设置了)
<settings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0
https://maven.apache.org/xsd/settings-1.1.0.xsd">
<!-- servers -->
<!-- mirrors -->
<profiles>
<profile>
<id>myprofile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<maven.repo.url>${env.MAVEN_REPO_URL}</maven.repo.url>
</properties>
</profile>
</profiles>
</settings>
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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>mygroup</groupId>
<artifactId>myparent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>myartifact</artifactId>
<name>myname</name>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>mynexus</id>
<name>nexus repository</name>
<url>${maven.repo.url}/public</url>
</repository>
</repositories>
<!-- build, etc. -->
</project>
我希望我应该能够在 pom.xml 中使用该属性maven.repo.url
,就像我在 pom.xml 中的其他任何地方使用它一样。它可以很好地下拉依赖项,它只是无法从远程 nexus 存储库中拉下我的父 pom。
这是Maven错误消息:
$ mvn $MAVEN_CLI_OPTS clean compile
[INFO] Scanning for projects...
[WARNING] Could not transfer metadata mygroup:myparent:1.0-SNAPSHOT/maven-metadata.xml from/to myrepo (${maven.repo.url}/public): Cannot access ${maven.repo.url}/public with type default using the available connector factories: BasicRepositoryConnectorFactory
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for mygroup:myartifact:1.0-SNAPSHOT: Could not transfer artifact mygroup:myparent:pom:1.0-SNAPSHOT from/to myrepo (${maven.repo.url}/public): Cannot access ${maven.repo.url}/public with type default using the available connector factories: BasicRepositoryConnectorFactory and 'parent.relativePath' points at wrong local POM @ line 3, column 10
@
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project mygroup:myartifact:1.0-SNAPSHOT (/builds/gitlab/group1/myartifact/pom.xml) has 1 error
[ERROR] Non-resolvable parent POM for mygroup:myparent:1.0-SNAPSHOT: Could not transfer artifact mygroup:myparent:1.0-SNAPSHOT from/to myrepo (${maven.repo.url}/public): Cannot access ${maven.repo.url}/public with type default using the available connector factories: BasicRepositoryConnectorFactory and 'parent.relativePath' points at wrong local POM @ line 3, column 10: Cannot access ${maven.repo.url}/public using the registered transporter factories: WagonTransporterFactory: Unsupported transport protocol -> [Help 2]
[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/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
ERROR: Job failed: exit code 1
解决方案
我发现我需要启用快照存储库才能下载父 pom 快照。这是更新的.m2/settings.xml:
<settings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0
https://maven.apache.org/xsd/settings-1.1.0.xsd">
<!-- servers -->
<!-- mirrors -->
<profiles>
<profile>
<id>myprofile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<maven.repo.url>${env.MAVEN_REPO_URL}</maven.repo.url>
</properties>
<repositories>
<repository>
<id>myrepo</id>
<url>${env.MAVEN_REPO_URL}/public</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
</settings>
奇怪的是,Apache Maven设置文档声明默认情况下启用快照。
遇到这篇文章,它为我指明了正确的方向。
推荐阅读
- python - 用 Python 编写期货(asyncio)
- asp.net-core - 如何注入对特定 IHostedService 实现的引用?
- python - Apache Beam 将每个标记的输出写入单独的文件
- javascript - 有谁知道为什么我在安装 airbnb 时收到此 eslint 错误消息
- spring-data-jpa - 无法在 JPA+spring Data 中设置简单的 LIKE+ignore case 查询
- ios - 如何在访问用户位置时添加自定义消息?
- python - 使用递归函数对整数进行洗牌
- azure-ad-b2c - Azure B2C - 如何添加额外的身份验证字段?
- python-3.x - 如何在熊猫数据框上制作矩形矩阵正方形
- sql - 如何 PIVOT SQL 表