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

Jenkins构建Maven项目时Nexus依赖解析失败问题求助

Troubleshooting "Non-resolvable import POM: Could not find artifact in Nexus" in Jenkins + Docker + OpenShift Demo

Let's break down how to diagnose and fix this issue step by step, since you're running all core services (Jenkins, Nexus) in Docker containers and working with the OpenShift Tasks repo for your CD demo:

  • Verify network connectivity between Jenkins and Nexus containers
    First, confirm Jenkins can reach your Nexus instance. Exec into the Jenkins container with docker exec -it <jenkins-container-name> /bin/bash, then run:

    • ping <nexus-container-name> (if they're on the same Docker network, container names should resolve automatically)
    • curl http://<nexus-host>:<nexus-port>/repository/maven-public/ to check if the repository endpoint is accessible.
      If either fails, make sure both containers are attached to the same custom Docker network (create one if needed with docker network create demo-network and re-run containers attached to it).
  • Check Maven settings.xml configuration in Jenkins
    Ensure Jenkins is using a Maven settings.xml that correctly points to your Nexus repository:

    • In Jenkins, go to Manage Jenkins > Global Tool Configuration > Maven > Maven installations, and confirm you've specified a custom settings.xml path (or configure it per job under Build > Advanced > Settings file).
    • Your settings.xml should include valid mirror and profile configurations for Nexus, like this example:
      <mirrors>
        <mirror>
          <id>nexus</id>
          <mirrorOf>central</mirrorOf>
          <url>http://<nexus-host>:<nexus-port>/repository/maven-public/</url>
        </mirror>
      </mirrors>
      <profiles>
        <profile>
          <id>nexus</id>
          <repositories>
            <repository>
              <id>central</id>
              <url>http://central</url>
              <releases><enabled>true</enabled></releases>
              <snapshots><enabled>true</enabled></snapshots>
            </repository>
          </repositories>
          <pluginRepositories>
            <pluginRepository>
              <id>central</id>
              <url>http://central</url>
              <releases><enabled>true</enabled></releases>
              <snapshots><enabled>true</enabled></snapshots>
            </pluginRepository>
          </pluginRepositories>
        </profile>
      </profiles>
      <activeProfiles>
        <activeProfile>nexus</activeProfile>
      </activeProfiles>
      

    If Nexus requires authentication, add a <servers> block with the correct username and password matching your Nexus user.

  • Confirm the missing artifact exists in Nexus
    Log into your Nexus web UI, use the search bar to look for the artifact specified in the error (copy the exact groupId, artifactId, version from your POM's import statement).

    • If it's a third-party dependency: Ensure your Nexus has a proxy repository for Maven Central, and this proxy is included in the maven-public group repository.
    • If it's a custom internal artifact: Make sure it was deployed to Nexus correctly (e.g., via mvn deploy from your local machine or a pre-build pipeline).
  • Validate the OpenShift Tasks POM configuration
    Double-check the <dependencyManagement> section in your project's POM where the import is defined. Ensure the coordinates (groupId, artifactId, version) match exactly what's stored in Nexus—typos here are a super common culprit.

  • Check Docker DNS resolution
    If you're using container names to reference Nexus in your Maven settings, ensure Docker's internal DNS is working reliably. As a quick test, replace the container name with Nexus's static IP address (find it with docker inspect <nexus-container-name> | grep IPAddress) in your settings.xml to bypass potential DNS issues.

  • Verify Jenkins build command settings
    In your Jenkins job configuration, make sure the Maven build command includes the correct settings file if you're not using the global one. For example:

    mvn clean install -s /var/jenkins_home/.m2/settings.xml
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 07:26:10