Maven父子结构的项目依赖使用以及打包依赖
1:在父子结构项目中,如果要是用其他模块的类。在当前项目中的pom中 加入 其他模块的配置
<dependency> <groupId>com.spring.mySpring</groupId> <artifactId>mySpring-utils</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency>
其中的groupId与artifactId还有version要与对应的模块一致
2:如果当前模块依赖其他模块,而且在打包的时候需要把依赖也打进去,则需要配置
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <!-- 指定程序的主类 --> <configuration> <mainClass>org.mySpring.service.TestService</mainClass> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
3:总的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>com.spring.mySpring</groupId> <artifactId>mySpring-parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>mySpring-service</artifactId> <name>mySpring-service</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <!-- 使用其他子模块的依赖 --> <dependency> <groupId>com.spring.mySpring</groupId> <artifactId>mySpring-utils</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> </dependencies> <!-- 打包的时候带其他的子模块 --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <!-- 指定程序的主类 --> <configuration> <mainClass>org.mySpring.service.TestService</mainClass> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>