maven使用flatten报错Failed to collect dependencies at com.test:test-common-core:jar:{revision}以及配置使用

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

maven的flatten插件的使用配置,以及出现找不到引入子模块版本的问题。


一、问题原因

1、报错信息

[ERROR] Failed to execute goal on project test-modules-system: Could not resolve dependencies 
for project com.test:test-modules-system:war:1.0: Failed to collect dependencies at 
com.test:test-common-core:jar:1.0: Failed to read artifact descriptor for com.test:test-common-
core:jar:1.0: The following artifacts could not be resolved: com.test:test-
common:pom:${revision} (absent): Could not transfer artifact com.

2、问题

maven使用flatten管理模块版本,可以install,启动项目包找不到本地子模块的版本。

3、原因

识别不出来flatten的版本,会自动去网上下载,找不到对应版本,配置不全时,会时灵时不灵的出现问题,另外端口卡到导致端口占用也会报依赖错误。

4、其他

端口占用项目启动的时候,可能也会报找不到依赖,可以参考之前发的文章。

二、配置修改

1.模块层级列表展示

test-module 父模块
– – – – test-common 公共模块
– – – – – – – – test-common-core 公共模块核心
– – – – test-modules 业务模块
– – – – – – – – test-system 系统模块

案例使用说明:
1、test-system模块引入test-common-core模块。
2、pom的配置信息忽略了多余|默认的配置信息。
3、test为项目名称,有内部信息,修改过。
4、配置改自若依管理系统的模块配置。

2.test-module的pom文件

<project>
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.test</groupId>
 <artifactId>test</artifactId>
 <version>${revision}</version>
 <packaging>pom</packaging>
 
 <modules>
     <module>test-modules</module>
     <module>test-common</module>
 </modules>
 
 <properties>
 	<!-- 项目定义的版本 -->
     <revision>1.0</revision>
     <!-- flatten插件定义的版本 -->
     <flatten-maven-plugin.version>1.5.0</flatten-maven-plugin.version>
 </properties>
 
 <!-- 依赖声明 -->
 <!-- 定义局部配置,别的模块使用需要引入 -->
 <dependencyManagement>
     <dependencies>
         <!-- 核心模块,用于别的模块引入 -->
         <!--
         推荐使用${project.version}管理子模块依赖版本(兼容不使用${revision}的模式),亦可直接使用${revision}。
         -->
         <dependency>
             <groupId>com.test</groupId>
             <artifactId>test-common-core</artifactId>
             <version>${project.version}</version>
         </dependency>
     </dependencies>
 </dependencyManagement>
 
 <build>
 	<plugins>
       <!-- 引入最外层父模块的flatten配置信息,子模块全部生效 -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>flatten-maven-plugin</artifactId>
        </plugin>
    </plugins>
 	<!-- 定义局部配置,别的模块使用时按需引入 -->
     <pluginManagement>
         <plugins>
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>flatten-maven-plugin</artifactId>
                 <version>${flatten-maven-plugin.version}</version>
                 <configuration>
                     <!-- 避免IDE将 .flattened-pom.xml 自动识别为功能模块 -->
                     <!-- 解决启动项目|打包,报网上下载找不到定义的版本信息,配置不全会出现不稳定报错问题 -->
                     <flattenedPomFilename>pom-xml-flattened</flattenedPomFilename>
                     <updatePomFile>true</updatePomFile>
                     <flattenMode>resolveCiFriendliesOnly</flattenMode>
                 </configuration>
                 <executions>
                     <execution>
                         <id>flatten</id>
                         <phase>process-resources</phase>
                         <goals>
                             <goal>flatten</goal>
                         </goals>
                     </execution>
                     <execution>
                         <id>flatten.clean</id>
                         <phase>clean</phase>
                         <goals>
                             <goal>clean</goal>
                         </goals>
                     </execution>
                 </executions>
             </plugin>
         </plugins>
     </pluginManagement>
 </build>

 <!-- 全局配置,别的子模块都已使用全局配置 -->
 <!-- 配置国内下载依赖 -->
 <repositories>
     <repository>
         <id>public</id>
         <name>aliyun nexus</name>
         <url>https://maven.aliyun.com/repository/public/</url>
         <releases>
             <enabled>true</enabled>
         </releases>
     </repository>
 </repositories>
 <!-- 配置国内下载插件 -->
 <pluginRepositories>
     <pluginRepository>
         <id>public</id>
         <name>aliyun nexus</name>
         <url>https://maven.aliyun.com/repository/public/</url>
         <releases>
             <enabled>true</enabled>
         </releases>
         <snapshots>
             <enabled>false</enabled>
         </snapshots>
     </pluginRepository>
 </pluginRepositories>
</project>

3.test-common的pom文件

<project>
    <modelVersion>4.0.0</modelVersion>
    
    <parent>
        <groupId>com.test</groupId>
        <artifactId>test</artifactId>
        <version>${revision}</version>
        <!-- 引入上一层的信息pom,用于获取revision的值 -->
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>test-common</artifactId>
    <packaging>pom</packaging>

    <description>
        test-common通用模块
    </description>

    <modules>
        <module>test-common-core</module>
    </modules>
</project>

4.test-common-core的pom文件

<project>
    <modelVersion>4.0.0</modelVersion>
    
    <parent>
        <groupId>com.test</groupId>
        <artifactId>test-common</artifactId>
        <version>${revision}</version>
        <!-- 引入上一层的信息pom,用于获取revision的值 -->
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>test-common-core</artifactId>

    <description>
        test-common-core核心模块
    </description>
</project>

5.test-modules的pom文件

<project>
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.test</groupId>
        <artifactId>test</artifactId>
        <version>${revision}</version>
        <!-- 引入上一层的信息pom,用于获取revision的值 -->
        <relativePath>../pom.xml</relativePath>
    </parent>

    <artifactId>test-modules</artifactId>
    <packaging>pom</packaging>

    <modules>
        <module>test-system</module>
    </modules>
</project>

6.test-system的pom文件

<project>
    <modelVersion>4.0.0</modelVersion>
    
    <parent>
        <groupId>com.test</groupId>
        <artifactId>test-modules</artifactId>
        <version>${revision}</version>
        <!-- 引入上一层的信息pom,用于获取revision的值 -->
        <relativePath>../pom.xml</relativePath>
    </parent>

    <!--改为war方式-->
    <!--<packaging>war</packaging>-->

    <artifactId>test-modules-system</artifactId>

    <description>
        test-modules-system 系统模块
    </description>
    
    <dependencies>
    	<!-- 调用最外层父模块声明的公共模块 -->
        <dependency>
            <groupId>com.test</groupId>
            <artifactId>test-common-core</artifactId>
        </dependency>
    </dependencies>

    <build>
        <!-- 打包后的文件名称 -->
        <finalName>test</finalName>
        
        <!-- 配置resources,指定配置文件(yml、xml等)打包-->
        
    </build>
</project>

参考

https://blog.youkuaiyun.com/luo15242208310/article/details/122874645


总结

参考很多内容,感谢各位帮助! ^v^
当项目 `com.ruoyi:data-joint:jar:3.6.6` 打包时无法解析依赖,找不到 `com.ruoyi:ruoyi-common:pom:3.6.6`,可以尝试以下解决办法: ### 检查仓库配置 确保项目的 Maven 配置文件(`pom.xml`)中配置的仓库包含了该依赖的来源。可能需要添加或修改仓库地址,例如: ```xml <repositories> <repository> <id>central</id> <url>https://repo.maven.apache.org/maven2</url> </repository> <!-- 可以添加其他自定义仓库 --> </repositories> ``` ### 清理本地仓库 有时候本地仓库中的缓存文件可能损坏,导致依赖无法正确解析。可以删除本地 Maven 仓库中该依赖的相关文件,然后重新构建项目。本地 Maven 仓库默认路径为 `~/.m2/repository`,找到 `com/ruoyi/ruoyi-common/3.6.6` 目录并删除,之后在项目根目录下执行以下命令重新构建: ```bash mvn clean install ``` ### 检查依赖版本 确认 `com.ruoyi:ruoyi-common` 的版本 `3.6.6` 是否存在。可能该版本并不存在于仓库中,可以尝试使用其他可用版本。在 `pom.xml` 中修改依赖版本: ```xml <dependency> <groupId>com.ruoyi</groupId> <artifactId>ruoyi-common</artifactId> <version>其他可用版本</version> </dependency> ``` ### 手动安装依赖 如果该依赖在远程仓库中确实存在,但由于网络或其他原因无法自动下载,可以手动下载该依赖的 `pom` 文件和 `jar` 文件,然后使用以下命令将其安装到本地仓库: ```bash mvn install:install-file -Dfile=path/to/ruoyi-common-3.6.6.jar -DgroupId=com.ruoyi -DartifactId=ruoyi-common -Dversion=3.6.6 -Dpackaging=jar ``` ### 检查网络连接 确保网络连接正常,能够访问配置的远程仓库。如果使用的是公司内部仓库或代理,需要确保代理配置正确。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值