无法传输工件:无法解释settings.xml属性

时间:2019-05-29 22:55:55

标签: apache maven gitlab-ci

我正在尝试使用以下项目在gitlab-ci上构建

  • 位于我们的关系存储库(不是父目录)上的父pom
  • 使用在 settings.xml
  • 中设置的maven.repo.url属性

当将repositories.repository.url中的${maven.repo.url}/public项替换为硬编码的url时,这与 pom.xml 一起使用。 http://localhost:8081/nexus/content/repositories/public。但是,当尝试使用 settings.xml 中设置的属性时,生成错误提示该问题

  

无法将工件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 (注意:我在GitLab组变量中设置了MAVEN_REPO_URL

<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 < / em>。对于拉下依赖项,它工作得很好,只是不能从远程关系存储库中拉出我的父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

1 个答案:

答案 0 :(得分: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 settings documentation指出快照是默认启用的。

在这个指向我正确方向的post上走来走去。