idea新建聚合项目并附上标签的详细过程

时间:2022-09-06 07:38:02

首先新建父工程

idea新建聚合项目并附上标签的详细过程

新建spring boot项目

idea新建聚合项目并附上标签的详细过程

填写项目信息

idea新建聚合项目并附上标签的详细过程

指定该子项目的路径

idea新建聚合项目并附上标签的详细过程

如果是组件类型的子项目 可以删除application.xml和启动类

父工程pom文件

  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  3.          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
  4.     <modelVersion>4.0.0</modelVersion> 
  5.     <groupId>com.demo</groupId> 
  6.     <artifactId>project</artifactId> 
  7.     <version>1.0.0-SNAPSHOT</version> 
  8.   
  9.     <properties> 
  10.         <spring-boot.version>2.3.5.RELEASE</spring-boot.version> 
  11.     </properties> 
  12.   
  13.     <modules> 
  14.         <module>common-mail</module> 
  15.     </modules> 
  16.   
  17.     <packaging>pom</packaging> 
  18.   
  19.     <dependencyManagement> 
  20.         <dependencies>    
  21.             <dependency> 
  22.                 <groupId>com.xx</groupId> 
  23.                 <artifactId>common-assembly</artifactId> 
  24.                 <version>${vanpeng.version}</version> 
  25.             </dependency> 
  26.         </dependencies> 
  27.     </dependencyManagement> 
  28.   
  29.     <dependencies> 
  30.         <!-- swagger --> 
  31.         <dependency> 
  32.             <groupId>io.swagger</groupId> 
  33.             <artifactId>swagger-annotations</artifactId> 
  34.             <version>1.5.10</version> 
  35.         </dependency> 
  36.     </dependencies> 
  37.   
  38.     <build> 
  39.         <plugins> 
  40.             <plugin> 
  41.                 <groupId>org.apache.maven.plugins</groupId> 
  42.                 <artifactId>maven-compiler-plugin</artifactId> 
  43.                 <configuration> 
  44.                     <source>${java.version}</source> 
  45.                     <target>${java.version}</target> 
  46.                     <encoding>${project.build.sourceEncoding}</encoding> 
  47.                 </configuration> 
  48.             </plugin> 
  49.         </plugins> 
  50.     </build> 
  51.   
  52. </project> 

<modules>:为包含的子工程artifactId名
<properties>:指常量 一般为版本号 方便统一修改
<dependencyManagement>:指定子工程有相同jar包时,使用父工程的版本号,而子工程不用在额外指定
<dependencies>:为父子工程可以同时引入的jar包

子工程pom文件

  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  3.          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
  4.     <modelVersion>4.0.0</modelVersion> 
  5.     <parent> 
  6.         <groupId>com.demo</groupId> 
  7.         <artifactId>project</artifactId> 
  8.         <version>1.0.0-SNAPSHOT</version> 
  9.     </parent> 
  10.   
  11.     <groupId>com.demo</groupId> 
  12.     <artifactId>common-assembly</artifactId> 
  13.     <version>1.0.0-SNAPSHOT</version> 
  14.   
  15.     <properties> 
  16.         <java.version>1.8</java.version> 
  17.         <spring-cloud.version>Hoxton.SR8</spring-cloud.version> 
  18.     </properties> 
  19.   
  20.     <dependencies> 
  21.         <!-- 此处可以引入其他子工程包 --> 
  22.         <dependency> 
  23.             <groupId>com.demo</groupId> 
  24.             <artifactId>common-resource</artifactId> 
  25.         </dependency> 
  26.     </dependencies> 
  27.   
  28.     <dependencyManagement> 
  29.         <dependencies> 
  30.             <dependency> 
  31.                 <groupId>org.springframework.cloud</groupId> 
  32.                 <artifactId>spring-cloud-dependencies</artifactId> 
  33.                 <version>${spring-cloud.version}</version> 
  34.                 <type>pom</type> 
  35.                 <scope>import</scope> 
  36.             </dependency> 
  37.         </dependencies> 
  38.     </dependencyManagement> 
  39.   
  40.     <build> 
  41.         <finalName>common-assembly-1.0.0-SNAPSHOT</finalName> 
  42.         <plugins> 
  43.             <plugin> 
  44.                 <groupId>org.springframework.boot</groupId> 
  45.                 <artifactId>spring-boot-maven-plugin</artifactId> 
  46.                 <configuration> 
  47.                     <includeSystemScope>true</includeSystemScope> 
  48.                     <mainClass>com.demo.assembly.BusinessApplication</mainClass> 
  49.                 </configuration> 
  50.                 <executions> 
  51.                     <execution> 
  52.                         <goals> 
  53.                             <goal>repackage</goal> 
  54.                         </goals> 
  55.                     </execution> 
  56.                 </executions> 
  57.             </plugin> 
  58.         </plugins> 
  59.     </build> 
  60.   
  61. </project> 
 <parent>:为父工程的信息 也就是父工程pom中的groupId,artifactId 必填  <build>:为打包时的配置
注意com.vanpeng.assembly.BusinessApplication一定要配置 否则jar包启动会找不到主函数 pom也必须配置 这是在父子工程中必须配置的 意思是 需要以方式引入 而不是打成jar

到此这篇关于idea新建聚合项目并附上标签详解的文章就介绍到这了,更多相关idea新建聚合项目内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/qq_20143059/article/details/117689469