我有一个多模块maven项目,其中有4个模块。
一个 乙 C D(D取决于A,B,C)
所有这些模块都有共同的依赖关系,如spring-data-mongodb等。
当我进行全新安装时,我希望所有上述常见依赖项都捆绑到D中,但maven也将它捆绑到A,B,C中,并且D的jar文件大小很大。
有没有办法让maven将所有上述常见的依赖关系,例如spring-data-mongodb等放在一个地方,让所有的A,B,C和D都在jar中使用它?
谢谢。
父母pom如下:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" 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>
<parent>
<groupId>io.spring.platform</groupId>
<artifactId>platform-bom</artifactId>
<version>2.0.1.RELEASE</version>
</parent>
<groupId>com.betcade</groupId>
<artifactId>betcade-core</artifactId>
<version>0.21</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<start-class>com.betcade.core.AppLauncher</start-class>
</properties>
<name>betcade-core</name>
<description>An aggregator project for a set of betcade core service related repositories</description>
<modules>
<module>A</module>
<module>B</module>
<module>C</module>
<module>D</module>
<dependencies>
<!-- Spring Boot Dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Spring Boot Dependencies -->
<!-- Apache Commons Dependencies -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.5.0</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<!-- Apache Commons Dependencies -->
<!-- Twilio SMS Gateway Dependency -->
<dependency>
<groupId>com.twilio.sdk</groupId>
<artifactId>twilio-java-sdk</artifactId>
<version>3.4.5</version>
</dependency>
<!-- Twilio SMS Gateway Dependency -->
<!-- Mandrill Mail API Dependency -->
<dependency>
<groupId>com.mandrillapp.wrapper.lutung</groupId>
<artifactId>lutung</artifactId>
<version>0.0.7</version>
</dependency>
<!-- Mandrill Mail API Dependency -->
<!-- MailGun API Dependency -->
<dependency>
<groupId>net.sargue</groupId>
<artifactId>mailgun</artifactId>
<version>1.0.0</version>
</dependency>
<!-- MailGun API Dependency -->
<!-- Spring AWS Dependencies -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-aws-context</artifactId>
<version>1.0.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-aws-messaging</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
<!-- AWS Dependencies -->
<!-- Joda Time Dependency -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
<!-- Joda Time Dependency -->
<!-- Quartz Scheduler Dependency -->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.2</version>
</dependency>
<!-- Quartz Scheduler Dependency -->
<!-- JSP Dependency -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!-- JSP Dependency -->
<!-- XML Parsing Dependencies -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.moxy</artifactId>
<version>2.6.3</version>
</dependency>
<dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId>
<version>2.7.1</version>
</dependency>
<!-- XML Parsing Dependencies -->
<!-- Apache POI Dependencies -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.14-beta1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.14-beta1</version>
</dependency>
<!-- Apache POI Dependencies -->
<!-- DynamicReports Dependencies -->
<dependency>
<groupId>net.sourceforge.dynamicreports</groupId>
<artifactId>dynamicreports-core</artifactId>
<version>4.1.0</version>
</dependency>
<!-- DynamicReports Dependencies -->
<!-- JWT Dependencies -->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.6.0</version>
</dependency>
<!-- JWT Dependencies -->
<!-- Timezone Dependencies -->
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>57.1</version>
</dependency>
<!-- Timezone Dependencies -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
PS:这是一个Spring启动项目。
答案 0 :(得分:1)
您的依赖关系捆绑在每个工件中,因为您已在根POM的<dependencies/>
中指定了它们。此列表应仅包含所有模块100%所需的依赖项。好的做法是首先使用根POM的<dependencyManagement/>
部分中的版本定义每个项目依赖项,然后在每个模块POM的<dependencies/>
部分中仅指定必要的依赖项。
答案 1 :(得分:0)
问题在于我的Sprint启动插件配置(在父pom中添加),它将所有相关的jar捆绑到项目的所有模块中。
将构建弹簧引导插件移动到适当的模块后,maven将所有相关的jar放入一个地方,一切都很好。