首先新建父工程
新建spring boot项目
填写项目信息
指定该子项目的路径
如果是组件类型的子项目 可以删除application.xml和启动类
父工程pom文件
- <?xml version="1.0" encoding="UTF-8"?>
- <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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <groupId>com.demo</groupId>
- <artifactId>project</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- <properties>
- <spring-boot.version>2.3.5.RELEASE</spring-boot.version>
- </properties>
- <modules>
- <module>common-mail</module>
- </modules>
- <packaging>pom</packaging>
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>com.xx</groupId>
- <artifactId>common-assembly</artifactId>
- <version>${vanpeng.version}</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
- <dependencies>
- <!-- swagger -->
- <dependency>
- <groupId>io.swagger</groupId>
- <artifactId>swagger-annotations</artifactId>
- <version>1.5.10</version>
- </dependency>
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>${java.version}</source>
- <target>${java.version}</target>
- <encoding>${project.build.sourceEncoding}</encoding>
- </configuration>
- </plugin>
- </plugins>
- </build>
- </project>
<modules>:为包含的子工程artifactId名
<properties>:指常量 一般为版本号 方便统一修改
<dependencyManagement>:指定子工程有相同jar包时,使用父工程的版本号,而子工程不用在额外指定
<dependencies>:为父子工程可以同时引入的jar包
子工程pom文件
- <?xml version="1.0" encoding="UTF-8"?>
- <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>com.demo</groupId>
- <artifactId>project</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- </parent>
- <groupId>com.demo</groupId>
- <artifactId>common-assembly</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- <properties>
- <java.version>1.8</java.version>
- <spring-cloud.version>Hoxton.SR8</spring-cloud.version>
- </properties>
- <dependencies>
- <!-- 此处可以引入其他子工程包 -->
- <dependency>
- <groupId>com.demo</groupId>
- <artifactId>common-resource</artifactId>
- </dependency>
- </dependencies>
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-dependencies</artifactId>
- <version>${spring-cloud.version}</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- </dependencies>
- </dependencyManagement>
- <build>
- <finalName>common-assembly-1.0.0-SNAPSHOT</finalName>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <configuration>
- <includeSystemScope>true</includeSystemScope>
- <mainClass>com.demo.assembly.BusinessApplication</mainClass>
- </configuration>
- <executions>
- <execution>
- <goals>
- <goal>repackage</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </project>
注意com.vanpeng.assembly.BusinessApplication一定要配置 否则jar包启动会找不到主函数 pom也必须配置 这是在父子工程中必须配置的 意思是 需要以方式引入 而不是打成jar
到此这篇关于idea新建聚合项目并附上标签详解的文章就介绍到这了,更多相关idea新建聚合项目内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://blog.csdn.net/qq_20143059/article/details/117689469