无法在 GitLab CI 管道中执行目标

Failed to execute goal in GitLab CI Pipeline

当我触发应用程序的构建管道时,出现无法执行目标错误。但是,当我在本地构建此应用程序时,不会出现此类异常。当我仅通过 GitLab 构建时,我会遇到这种情况。

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean) on project sample-app: Execution default-clean of goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean failed: Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to collect dependencies at org.apache.maven.plugins:maven-clean-plugin:jar:2.5 -> org.apache.maven:maven-plugin-api:jar:2.0.6: Failed to read artifact descriptor for org.apache.maven:maven-plugin-api:jar:2.0.6: Could not transfer artifact org.apache.maven:maven-plugin-api:pom:2.0.6 from/to central (https://repo.maven.apache.org/maven2): Connection reset -> [Help 1]

为了更好看,下面还附上了错误图片...

我们正在与我的团队一起调查此问题的根本原因,但我们无法找到解决方案。然而,最常见的原因是不同服务器中的 GitLab-Runner 运行 存在连接问题,因此会发生这种情况。

我的一个团队成员找到了一个解决方案并且对我们有用。我们的问题已解决,现在 GitLab 管道已成功构建并运行。这对我们有用,希望遇到类似问题的任何人也会觉得这很有帮助。

  <pluginRepositories>
    <pluginRepository>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
    </pluginRepository>
  </pluginRepositories>
  <repositories>
    <repository>
      <id>central</id>
      <name>Central Repository</name>
      <url>https://repo.maven.apache.org/maven2</url>
      <layout>default</layout>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
  <repositories>

将上述代码块添加到 POM 文件解决了问题。