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.csdn.net/luo15242208310/article/details/122874645


总结

参考很多内容,感谢各位帮助! ^v^
  • 14
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值