Skip to content

如何将多个 maven 项目统一管理

Posted on:March 22, 2018 at 10:21 AM

简介

在我们一个人采用微服务构架的时候,我们会创建很多个 maven 项目。然后如果从 IDE 里面导入项目就要导入很多次,为了方便统一管理,我们可以将多个 maven 放在一个 项目里统一管理,然后我们导入项目的时候就可以直接导入一个项目就 OK。

操作方法

<?xml version="1.0" encoding="UTF-8"?>
<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>com.lxr</groupId>
	<artifactId>maiba_be</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<!-- packaging 把 jar 改成 pox -->
	<packaging>pom</packaging>

    <!-- 这里面放每个微服务的 artifactId-->
    <modules>
        <module>goodsService</module>
    </modules>

    <!-- 为了解决依赖版本问题 -->
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>Camden.SR3</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.4.2.RELEASE</version>
	</parent>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<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>

    
	<artifactId>goodsService</artifactId>
	<packaging>jar</packaging>

    <!-- 这里的 artifactId 更改为父 pox.xml 的 artifactId -->
	<parent>
		<groupId>com.lxr</groupId>
		<artifactId>maiba_be</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>

    <!-- 下面的依赖 根据需求 -->
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>

		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<scope>runtime</scope>
		</dependency>

	</dependencies>
</project>