Maven父子结构的项目依赖使用以及打包依赖_微服务项目(maven父子级项目)怎么打包
2023-09-14 09:14:53 时间
Maven父子结构的项目依赖使用以及打包依赖
1:在父子结构项目中,如果要是用其他模块的类。在当前项目中的pom中 加入 其他模块的配置
<dependency>
<groupId>com.spring.mySpring</groupId>
<artifactId>mySpring-utils</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
其中的groupId与artifactId还有version要与对应的模块一致
2:如果当前模块依赖其他模块,而且在打包的时候需要把依赖也打进去,则需要配置
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- 指定程序的主类 -->
<configuration>
<mainClass>org.mySpring.service.TestService</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
3:总的pom示例如下
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.spring.mySpring</groupId>
<artifactId>mySpring-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>mySpring-service</artifactId>
<name>mySpring-service</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- 使用其他子模块的依赖 -->
<dependency>
<groupId>com.spring.mySpring</groupId>
<artifactId>mySpring-utils</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<!-- 打包的时候带其他的子模块 -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- 指定程序的主类 -->
<configuration>
<mainClass>org.mySpring.service.TestService</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
微服务项目(maven父子级项目)怎么打包
项目层级结构:
common中的是没有main方法的工具类,service中的是有main方法的业务代码。
打包须知
这种微服务项目或者说是maven父子级项目打包要解决的问题就是具体业务代码依赖工具类代码,利用idea的maven插件可以很方便做到。
- 在cloud_parent,common,service这些上层文件夹管理模块中,添加
pom
- 在没有main方法的工具模块中只添加
jar
- 在具体的业务代码模块中添加:
<packaging>jar</packaging>
<build>
//maven的打包插件
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
//打包规则,打包时将resource文件夹打包进去
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.yml</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.yml</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
根据maven的继承特性,我在service文件夹模块中添加
这样,只需在每个有mian方法的具体的业务模块中的pom中添加:
<build>
//maven的打包插件
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
最终打包:只需对最顶层模块进行clean,install,在每个模块对应的target目录中找到jar包。
最后附上maven配置:
相关文章
- Zsh(oh-my-zsh)的Maven自动提示插件(zsh-maven-complection)
- springboot 项目maven 打包错误
- maven项目打包时生成dependency-reduced-pom.xml
- 【技术贴】Maven打包文件增加时间后缀
- maven Missing artifact com.sun:tools:jar:1.5.0
- Jenkins:用maven在本地打包部署一个github的springboot项目(Jenkins 2.257)
- IntellJ idea maven打包——项目带有第三方jar包
- maven-assembly-plugin 和 maven-shade-plugin打包插件的区别
- maven项目打包成可执行jar插件
- Atitit maven配置pom文件 配置法v2 t33 目录 1. Maven打包war原理1 1.1. 在target目录生成war包ori目录。。。里面就是所有的资源1 1.2. 去掉
- maven 添加本地jar包并打包
- Maven自定义上传第三方包到3rd party(第三方无依赖jar和本地扩展类加入maven统一管理)
- 【项目实战】使用Maven插件(jacoco-maven-plugin),实现生成代码覆盖率报告
- Spring Boot——maven项目常用打包配置
- maven - 多模块打包 -每个模块 多 环境 yml 的具体配置
- Maven插件系列之spring-boot-maven-plugin
- 使用Maven构建的Springboot父子工程的项目打包部署
- 【Docker】在本地打包maven程序为docker镜像报错: Connect to localhost:2375 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1]
- Error:Could not find com.github.dcendents:android-maven-plugin:1.5.
- 【异常】Maven构建出错,Could not transfer artifact xxx from/to central (https://repo.maven.apache.org/maven2)
- 【超详细】阿里/华为云服务器部署环境快速搭建一条龙【git、maven、jdk8、docker安装nginx、mysql、redis】
- 从零教你使用Maven,从此项目打包不用愁