没加载出来就reimport,这个时候clean和install没用,那是编译安装项目的。
结合idea的maven教程
子模块不需要groupId
先安装父再是子?dubbo官网案例:
为了成功编译服务端、消费端模块,需要先在本地打包安装 dubbo-samples-spring-boot-interface 模块。
./mvnw clean install -pl 1-basic/dubbo-samples-spring-boot
./mvnw clean install -pl 1-basic/dubbo-samples-spring-boot/dubbo-samples-spring-boot-interface
曾经我们在一个应用(一个war or jar)中划分出包(层是以包的层次结构划分的)。随着项目体积的逐渐增大,项目结构逐渐横向扩张变得臃肿(短粗):
---- app-parent
|-- pom.xml (pom)
|
|-- app-util
| |-- pom.xml (jar)
|
|-- app-dao
| |-- pom.xml (jar)
|
|-- app-service
| |-- pom.xml (jar)
|
|-- app-web
|-- pom.xml (war)
较好的描述
配置文件随意,会在作用域内按优先级生效。我猜是就近原则
springboot多模块简单来说,就是把按包分模块的模式,借助maven升级到jar的方式,抽象性更加强了,假如jar再升级到到war或者多个集合jar,就成微服务了,在多模块jar模式下可以将某个jar拿出来对外共用,能大大提高代码复用率与开发效率。
https://zhuanlan.zhihu.com/p/345682526
创建时选择:
maven pom
不以springboot为父项目的子模块需要加入这个依赖
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-dependenciesartifactId>
<version>2.5.9version>
<type>pomtype>
<scope>importscope>
dependency>
<modules>
<module>ruoyi-adminmodule>
<module>ruoyi-frameworkmodule>
<module>ruoyi-systemmodule>
<module>ruoyi-quartzmodule>
<module>ruoyi-generatormodule>
<module>ruoyi-commonmodule>
modules>
<packaging>pompackaging>
定义属性,如版本号等,可以自定义标签。
<properties>
<ruoyi.version>4.7.2ruoyi.version>
<project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8project.reporting.outputEncoding>
<java.version>1.8java.version>
<maven-jar-plugin.version>3.1.1maven-jar-plugin.version>
properties>
在后面用${}取出来用。在子模块中也可以使用父模块的属性。
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
<version>2.1.1.RELEASEversion>
<configuration>
<fork>truefork>
configuration>
<executions>
<execution>
<goals>
<goal>repackagegoal>
goals>
execution>
executions>
plugin>
创建时选择: maven project
一个通用模块,其他模块需要的时候在pom.xml中依赖他就行;实体类、注解、配置类、异常、util等都在这里
注:父模块中导入的依赖,子模块的pom.xml中依然需要编写配置(但可以省略父模块中已经声明的版本号)。
可以省略的(默认导入的)是通过标签依赖的模块中的依赖。
如果想要排除部门这些默认导入的模块,要指定exclusive
模块版本modelVersion和父工程版本不一样(4.0.0和4.7.2)
若依里,通用的在common里,主要业务在framework里。admin就光controller层?其他模块依赖common模块,common没有依赖其他,不然会循环依赖。admin不需要指明依赖common,因为依赖了依赖common的许多模块。(父工程下的大哥)
maven 打包问题(repackage failed: Unable to find main class)
问题背景:今天用spring boot做了一个公共模块,需要打成jar包,让其他项目引用,但打包的时却提示缺少主类,但是我这一个公共模块,本来就没写主类。
错误信息:repackage failed: Unable to find main class
问题原因为使用spring boot项目,用的maven插件为
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
<version>2.2.9.RELEASEversion>
plugin>
plugins>
用此插件打包时候会默认寻找签名是public static void main(String[] args)的方法,没有所以报错,
可以修改配置解决此问题。配置如下:
org.springframework.boot
spring-boot-maven-plugin
true
或者直接修改maven插件,改用apache的maven插件,配置如下:
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-compiler-pluginartifactId>
plugin>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.pluginsgroupId>
<artifactId>maven-compiler-pluginartifactId>
<configuration>
<source>${java.version}source>
<target>${java.version}target>
<encoding>${project.build.sourceEncoding}encoding>
configuration>
plugin>
plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-maven-pluginartifactId>
<version>${spring-boot.version}version>
<executions>
<execution>
<goals>
<goal>repackagegoal>
goals>
execution>
executions>
plugin>
plugins>
pluginManagement>
build>
spring-boot-maven-plugin
parent
dependiences
需要注意的是,之所以引入各starter、相关依赖的时候都不写版本,因为都有统一的父模块来管理版本;
无论是以springboot-parent为父模块,还是以包含的springboot-dependience的模块为父模块;在maven种,想省略版本号都是子项目;
https://blog.csdn.net/changerzhuo_319/article/details/99710393
https://blog.csdn.net/changerzhuo_319/article/details/99710872