0

在 OpenShift 中,我使用的是 s2i(docker strategy)。我在 pom.xml 中配置了两个 repo 的 public 和 private。

maven 能够从公共 repo 中提取工件,但它不能从私有 repo 中提取应用程序特定的工件。

有没有办法通过提供 maven repo 凭据来更新 openshift 中的 maven setting.xml。如何提供凭据以从配置的私有 Maven 存储库中提取工件。

下面的错误

从中央下载:https ://artifactory.mycomp.com/artifactory/java-snapshot-local/com/test/common-security/1.0.0/common-security-1.0.0.pom

无法在项目演示应用程序上执行目标:无法解析项目 com.example:demo-app:jar:0.0.1-SNAPSHOT 的依赖项:无法在 com.mycomp:common-security:jar:1.0.0 收集依赖项:无法读取 com.mycomp:common-security:jar:1.0.0 的工件描述符:无法将工件 com.mycomp:common-security:pom:1.0.0 从/到中央传输(https://artifactory.mycomp .com/artifactory/java-snapshot-local ): https ://artifactory.mycomp.com/artifactory/java-snapshot-local/com/test/common-security/1.0.0/common-security-1.0 的身份验证失败.0.pom,状态:401 Unauthorized -> [Help 1] [ERROR]

4

1 回答 1

1

下面的一个对我有用,但不确定这个是否理想。将 settings.xml 添加到源的根目录:

<settings>
    <servers>
        <server>
            <id>${repo.id}</id>
            <username>${repo.login}</username>
            <password>${repo.pwd}</password>
        </server>
    </servers>
</settings> 

在 docker 内部,用户可以在构建期间使用 settings.xml 作为参数并提供凭据。

# Build the application first using Maven
FROM maven:3.8-openjdk-11 as build
WORKDIR /app
COPY . .
COPY settings.xml /usr/share/
RUN mvn --version
RUN mvn --settings /usr/share/settings.xml -Drepo.id=central -Drepo.login=Myname -Drepo.pwd=MyPass clean install -Dmaven.test.skip=true

# Inject the JAR file into a new container to keep the file small
FROM openjdk:8-jre-alpine
WORKDIR /app
COPY --from=build /app/target/demo-app*.jar /app/app.jar
EXPOSE 8080
ENTRYPOINT ["sh", "-c"]
CMD ["java -jar app.jar"]
于 2022-02-02T11:00:47.330 回答