公共模块如实体模块common 不需要入口 先install放进maven本地仓库,然后再对依赖它的模块打包。
common 和父类的pom.xml配置不需要:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
因为此插件将项目打包成可执行jar包,所以每个需要打包的项目模块需要这个插件。
所有子模块 父模块改为如下:
<parent>
<groupId>com.shop</groupId>
<artifactId>shop</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
父模块的parent为:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
父模块引入子模块:
<modules>
<module>admin</module>
<module>cloudserver</module>
<module>common</module>
<module>shopuser</module>
</modules>
父模块加入:
<packaging>pom</packaging>
子模块加入:
<packaging>jar</packaging>
打成jar包。
在父模块进行依赖管理:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>2020.0.3</version> //主要是管理版本号
</dependency>
</dependencies>
</dependencyManagement>
在每个项目的target中有可以运行的jar包,使用 java -jar ~.jar 可以在本地运行。 在子模块中可以有依赖的版本号。记得clean, clean就是将新建的target删除,再package。
在父模块properties加入以下行可以跳过测试,子模块不需要properties标签,因为会继承父模块properties。
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
***<skipTests>true</skipTests>***
</properties>