在eclipse里面建立一个maven项目,选择类型为quickstart。
编写父pom;
<packaging>jar</packaging>
更改为
<packaging>pom</packaging>
然后在依赖里面加入spring-boot依赖,注意此处的范围了import
此处需要加上<dependencyManagement>此处会对jar版本进行控制;
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>1.5.4.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency>
这样就将springboot依赖包放到父pom里面了。
在properties里加入jdk版本,在编译插件里设置jdk版本,这样在maven中升级项目jdk版本就可以限定住了。
<properties> <jdk.version>1.8</jdk.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties>
编写插件
<build> <!-- 编译后生成jar文件的名称 --> <finalName>spring-boot-father</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${jdk.version}</source> <target>${jdk.version}</target> <encode>${project.build.sourceEncoding}</encode> </configuration> </plugin> </plugins> </build>
修改后的pom如下
<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>spring-boot</groupId> <artifactId>Father</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <name>Father</name> <url>http://maven.apache.org</url> <properties> <jdk.version>1.8</jdk.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>1.5.4.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <!-- 编译后生成jar文件的名称 --> <finalName>spring-boot-father</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${jdk.version}</source> <target>${jdk.version}</target> <encode>${project.build.sourceEncoding}</encode> </configuration> </plugin> </plugins> </build> <modules> <module>son</module> </modules> </project>
然后新建maven module;(子模块)
然后在子模块加入依赖包
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
修改后的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>spring-boot</groupId> <artifactId>Father</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>son</artifactId> <name>son</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> </project>
此时就可以编写代码了,如果还有其他模块,则依次添加就可以了,
注意模块之间不要互相依赖,这样在构建时候会形成死循环。
github地址:https://github.com/sona0402/springboot-quickstart.git