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

Jenkins构建Maven项目无法解析calculatrice依赖求助

解决Jenkins构建时Maven无法解析calculatrice模块依赖的问题

错误信息:

[ERROR] Failed to execute goal on project calculatrice-web:
Could not resolve dependencies for project fr.dawan:calculatrice-web:war:0.0.1-SNAPSHOT: The following artifacts could not be resolved: fr.dawan:calculatrice:jar:0.0.1-SNAPSHOT (absent): Could not find artifact fr.dawan:calculatrice:jar:0.0.1-SNAPSHOT -> [Help 1]

问题分析

calculatrice-web依赖的fr.dawan:calculatrice:jar:0.0.1-SNAPSHOT模块未被Maven找到,核心原因是该模块没有出现在Jenkins服务器可访问的Maven仓库(本地仓库或远程私有仓库)中。

解决方案

1. 采用多模块项目构建(推荐)

如果calculatrice和calculatrice-web属于同一个父项目的子模块:

  • 在父项目的pom.xml中声明两个子模块:
<modules>
    <module>calculatrice</module>
    <module>calculatrice-web</module>
</modules>
  • 修改Jenkins构建任务,拉取整个父项目并执行mvn clean install,Maven会自动按顺序构建并安装子模块依赖。

2. 独立构建并安装calculatrice模块

如果两个项目是独立仓库:

  • 在Jenkins中创建单独的构建任务,拉取calculatrice项目并执行命令:
mvn clean install
  • 该命令会将calculatrice的jar包安装到Jenkins服务器的本地Maven仓库(默认路径:~/.m2/repository/fr/dawan/calculatrice/0.0.1-SNAPSHOT/)。
  • 在calculatrice-web的Jenkins任务中添加构建依赖,确保calculatrice任务执行完成后再启动当前任务。

3. 检查Maven仓库配置

  • 如果使用私有远程仓库,需先将calculatrice部署到私有仓库,并在calculatrice-web的pom.xml中配置仓库地址:
<repositories>
    <repository>
        <id>your-private-repo</id>
        <url>http://your-repo-url/repository/maven-snapshots/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>
  • 确保Jenkins使用的settings.xml(本地路径~/.m2/settings.xml或Jenkins全局配置)包含私有仓库的认证信息(若需要)。

4. 验证依赖配置准确性

核对calculatrice-web的依赖配置与calculatrice的pom.xml信息完全一致:

<dependency>
    <groupId>fr.dawan</groupId>
    <artifactId>calculatrice</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>

确保groupId、artifactId、version无拼写错误,且calculatrice的打包类型为jar(默认无需额外配置)。

附用户提供的calculatrice-web的pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>fr.dawan</groupId>
    <artifactId>calculatrice-web</artifactId>
    
    <packaging>war</packaging>
    
    <version>0.0.1-SNAPSHOT</version>
    <name>calculatrice-web</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        
        <dependency>
            <groupId>fr.dawan</groupId>
            <artifactId>calculatrice</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        
        <dependency>
            <groupId>jakarta.validation</groupId>
            <artifactId>jakarta.validation-api</artifactId>
        </dependency>
        
    </dependencies>

    <build>
    <finalName>calculator-app</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <url>http://localhost:8080/manager/text</url>
                    <username>admin</username>
                    <password>admin</password>
                    <path>/calculator-app</path>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 15:58:14