Maven Nexus 问题 - 403 Forbidden 授权失败

问题描述 投票:0回答:2

我们已经讨论这个问题好几天了。

为从 Maven 和 Nexus 读取依赖项的 Java 应用程序创建了一个 Gitlab CI 管道

gitlab pipeline被配置为以具有管理员权限的nexus用户运行,这一点已被多次验证。

但是,当执行 gitlab 管道时,我们得到以下错误:

[ERROR] Failed to execute goal on project hello-component: Could not resolve dependencies for project x.y.z:hello-component:jar:1.6-SNAPSHOT: Failed to collect dependencies at a.b:c:jar:4.5.1132100: Failed to read artifact descriptor for b:c:jar:4.5.1132100: Could not transfer artifact a.b:c:pom:4.5.1132100 from/to maven-snapshots (http://host:8081/repository/maven-snapshots): Authorization failed for http://host:8081/repository/maven-snapshots/a/b/c/4.5.1132100/nidp-4.5.1132100.pom 403 Forbidden -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project hello-component: Could not resolve dependencies for project x.y.z:hello-component:jar:1.6-SNAPSHOT: Failed to collect dependencies at a.b:c:jar:4.5.1132100

我还使用了以下指南:

https://blog.sonatype.com/how-to-use-gitlab-ci-with-nexus

我的 POM 具有以下内容,在 ci/cd/settings/variables 中配置了 env 变量:

     <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.22.1</version>
                </plugin>
                <plugin>
                    <groupId>org.sonatype.plugins</groupId>
                    <artifactId>nexus-staging-maven-plugin</artifactId>
                    <version>1.5.1</version>
                    <executions>
                        <execution>
                            <id>default-deploy</id>
                            <phase>deploy</phase>
                            <goals>
                                <goal>deploy</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <serverId>maven-snapshots</serverId>
                        <nexusUrl>http://host:8081/repository/maven-snapshots</nexusUrl>
                        <skipStaging>true</skipStaging>
                    </configuration>
                </plugin>
            </plugins>
        </build>

<repositories>
        <repository>
            <id>maven-snapshots</id>
            <url>http://host:8081/repository/maven-snapshots</url>
        </repository>
        <repository>
            <id>maven-releases</id>
            <url>http://host:8081/repository/maven-releases</url>
        </repository>
        <!--repository>
            <id>nexus.local</id>
            <url>$HOME/.m2/repository</url>
        </repository-->
    </repositories>

    <distributionManagement>
        <snapshotRepository>
            <id>maven-snapshots</id>
            <url>http://host:8081/repository/maven-snapshots</url>
        </snapshotRepository>
        <repository>
            <id>maven-releases</id>
            <url>http://host:8081/repository/maven-releases</url>
        </repository>
    </distributionManagement>

Gitlab CI runner 有以下内容:

image: maven:3.3.9-jdk-8

variables:
  GIT_STRATEGY: clone
  MAVEN_CLI_OPTS: "-s /opt/apache-maven-3.6.3/conf/settings.xml --batch-mode"
  MAVEN_OPTS: "-Dmaven.repo.local=/home/gitlab-runner/.m2/repository"

cache:
  paths:
    - /home/gitlab-runner/.m2/repository/
    - target/

stages:
  - build

CodeBuild:
  stage: build
  script:
   - /opt/apache-maven-3.6.3/bin/mvn $MAVEN_CLI_OPTS -X clean package
  artifacts:
    name: “x—y-component"
    paths:
      - ./target/x—y-component.jar

gitlab ci服务器上的Setting.xml有如下nexus用户参考:

Maven 快照 [管理员用户] [管理员密码]

任何帮助将不胜感激。

谢谢

java maven gitlab nexus gitlab-ci-runner
2个回答
0
投票

不确定是否仍然需要帮助,但似乎您没有为您用于部署/解决依赖关系的用户角色授予必要的权限。请授予角色 nx-repository-view---* 权限。对其进行测试,然后您可以根据需要缩小范围。


0
投票

当时的问题是公司代理阻止从 maven central 等下载

编辑您的 maven settings.xml 中的代理部分,它可能位于您的 ~/.m2/settings.xml 文件中。 Settings.xml 也存在于您的 MAVEN_HOME 中,因此请确保您正在更新正确的 settings.xml

<settings>
<proxies>
    <proxy>
        <id>httpproxy</id>
        <active>true</active>
        <protocol>http</protocol>
        <host>your-proxy-host</host>
        <port>your-proxy-port</port>
        <nonProxyHosts>add.host.that.needs.to.bypass.proxy.here|some.host.com</nonProxyHosts>
    </proxy>
<proxy>
        <id>httpsproxy</id>
        <active>true</active>
        <protocol>https</protocol>
        <host>your-proxy-host</host>
        <port>your-proxy-port</port>
        <nonProxyHosts>add.host.that.needs.to.bypass.proxy.here|some.host.com</nonProxyHosts>
    </proxy>

</proxies>
</settings>
© www.soinside.com 2019 - 2024. All rights reserved.