You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitLab中Quarkus项目Maven Failsafe验证阶段仓库使用异常

问题:GitLab CI中Quarkus集成测试阶段错误拉取Snapshot仓库依赖

我有一个包含集成测试的Quarkus应用,pom.xml中定义了snapshot和release两个Profile:当以-Drelease=true执行verify构建时,应激活release Profile并使用release仓库。本地执行build或verify命令时能正确使用release仓库,但在GitLab中,build阶段可正常使用release仓库,verify阶段却从snapshot仓库下载依赖,甚至尝试下载在两个仓库都不存在的版本model:status.rest.api:jar:1.4.1-20221026.115121-1,最终报错。Maven日志显示已激活正确的release Profile,无法确定是Quarkus、Maven、JDK还是GitLab的问题。


相关配置

pom.xml Profiles

<profiles>
        <profile>
            <id>snapshot</id>
            <activation>
                <property>
                    <name>release</name>
                    <value>!true</value>
                </property>
                <activeByDefault>true</activeByDefault>
            </activation>
            <repositories>
                <repository>
                    <id>commons snapshot</id>
                    <url>http://url.de/maven/commons-snapshot</url>
                </repository>
            </repositories>
        </profile>
        <profile>
            <id>release</id>
            <activation>
                <property>
                    <name>release</name>
                    <value>true</value>
                </property>
            </activation>
            <repositories>
                <repository>
                    <id>commons release</id>
                    <url>http://url.de/maven/commons-release</url>
                </repository>
            </repositories>
        </profile>
  </profiles>

pom.xml Failsafe插件配置

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
        <execution>
            <goals>
                <goal>integration-test</goal>
                <goal>verify</goal>
            </goals>
            <configuration>
                <failIfNoTests>true</failIfNoTests>
                <skip>${skipITs}</skip>
                <includes>**/*IT*</includes>
                <excludes>**/*Test*</excludes>
                <systemPropertyVariables>
                    <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
                    <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
                    <maven.settings>.mvn/local-settings.xml</maven.settings>
                </systemPropertyVariables>
            </configuration>
        </execution>
    </executions>
</plugin>

/.mvn/local-settings.xml

<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd">
    <mirrors>
        <mirror>
            <id>maven-default-http-blocker</id>
            <mirrorOf>external:dummy:*</mirrorOf>
            <name>Pseudo repository to mirror external repositories initially
                using HTTP.
            </name>
            <url>http://0.0.0.0/</url>
            <blocked>false</blocked>
        </mirror>
    </mirrors>
</settings>

gitlab-ci.yml

variables:
  MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true -Drelease=$RELEASE"
  MAVEN_CLI_OPTS: "--batch-mode --errors --show-version --fail-at-end help:active-profiles"

image: maven:3-openjdk-17

cache:
  key: $CI_COMMIT_REF_SLUG

stages:
    - build
    - verify

build:
  stage: build
  script:
    - mvn $MAVEN_CLI_OPTS compile
  artifacts:
    paths:
     - "target/"
    expire_in: 1 week

verify:
  stage: verify
  needs: 
    - job: build
      artifacts: true
  script:
    - mvn $MAVEN_CLI_OPTS verify
  artifacts:
    when: always
    reports:
      junit:
        - target/failsafe-reports/TEST-*.xml
        - target/surefire-reports/TEST-*.xml

GitLab CI Verify阶段错误日志

230318 [INFO] -------------------------------------------------------
230318 [INFO]  T E S T S
230318 [INFO] -------------------------------------------------------
231542 [INFO] Running eu.gemtec.star.asterisk.integration.ITBase

ITBase是一个@QuarkusIntegrationTest,随后出现错误的仓库下载记录:

Downloaded from commons snapshot: http://url.de/maven/commons-snapshot/eu/model/model1/1.1.0-SNAPSHOT/device-1.1.0-20230308.144121-1.jar (9.9 kB at 12 kB/s)

最终报错:

Caused by: org.eclipse.aether.transfer.ArtifactNotFoundException: Could not find artifact model:status.rest.api:jar:1.4.1-20221026.115121-1 in commons snapshot (http://url.de/maven/commons-snapshot)
    at org.eclipse.aether.connector.basic.ArtifactTransportListener.transferFailed(ArtifactTransportListener.java:48)
    at org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run(BasicRepositoryConnector.java:369)
    at org.eclipse.aether.util.concurrency.RunnableErrorForwarder$1.run(RunnableErrorForwarder.java:75)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)

环境信息

Linux runner-wgxkyhte-project-39-concurrent-0 5.15.0-70-generic #77-Ubuntu SMP Tue Mar 21 14:02:37 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

openjdk 17.0.2 2022-01-18

Quarkus version 2.16.6.Final

Apache Maven 3.8.5 (3599d3414f046de2324203b78ddcf9b5e4388aa0)

问题分析与解决方案

核心原因

Quarkus的@QuarkusIntegrationTest会启动独立的应用实例,这个过程会重新解析依赖,而Failsafe插件默认不会传递Maven主构建的系统属性(比如release),导致集成测试阶段默认激活了snapshot Profile,从而错误拉取Snapshot仓库的依赖。

解决步骤

  1. 给Failsafe插件传递release系统属性
    修改pom.xml中的Failsafe插件配置,在systemPropertyVariables中添加release参数,确保集成测试能获取到Profile激活条件:
<systemPropertyVariables>
    <native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
    <java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
    <maven.settings>.mvn/local-settings.xml</maven.settings>
    <release>${release}</release> <!-- 新增这一行 -->
</systemPropertyVariables>
  1. 确认GitLab CI变量传递有效性
    在verify阶段的script中添加变量打印,确认RELEASE变量正确赋值:
verify:
  stage: verify
  needs: 
    - job: build
      artifacts: true
  script:
    - echo "RELEASE variable value: $RELEASE"
    - mvn $MAVEN_CLI_OPTS verify
  1. 显式激活Release Profile(备选方案)
    如果系统属性传递无效,可以在verify阶段的Maven命令中直接指定激活release Profile,跳过属性判断逻辑:
verify:
  stage: verify
  needs: 
    - job: build
      artifacts: true
  script:
    - mvn $MAVEN_CLI_OPTS -Prelease verify
  1. 清理缓存避免干扰
    GitLab CI的缓存可能保留了Snapshot阶段的依赖元数据,可临时修改缓存key或添加-U参数强制更新依赖:
verify:
  stage: verify
  needs: 
    - job: build
      artifacts: true
  script:
    - mvn $MAVEN_CLI_OPTS verify -U

内容的提问来源于stack exchange,提问作者unrated

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 15:47:02