springboot parent pom management

Create a maven project in eclipse and select the type as quickstart.

write parent pom;

<packaging>jar</packaging>

change to

<packaging>pom</packaging>

Then add the spring-boot dependency in the dependency, pay attention to the scope of import here

You need to add <dependencyManagement> here to control the jar version;

 

 

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-dependencies</artifactId>
   <version>1.5.4.RELEASE</version>
   <type>pom</type>
   <scope>import</scope>
</dependency>

 

 

This puts the springboot dependency package into the parent pom.

 

Add the jdk version in the properties, and set the jdk version in the compilation plugin, so that upgrading the project jdk version in maven can be limited.

 

<properties>
   <jdk.version>1.8</jdk.version>
   <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

 

Write a plugin

 

<build>
        <!-- The name of the jar file generated after compilation-->
	<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>

 

The modified pom is as follows

 

 

<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

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326218277&siteId=291194637