Maven冗余构建
问题描述:
我有一个多模块maven项目,其中有4个模块。Maven冗余构建
甲 乙 Ç d(d取决于A,B,C)
所有这些模块具有像普通的依赖弹簧数据的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:这是一个春天启动的项目。
答
问题在于我配置了Sprint启动插件(在父pom中添加),该插件将所有依赖的jar捆绑到项目的所有模块中。
一旦我将构建弹簧启动插件移动到适当的模块,maven把所有依赖的jar放到一个地方,事情都很好。
答
因为您已经在根POM的<dependencies/>
中指定了它们,所以您的依赖项将捆绑在每个工件中。这个列表应该只包含所有模块100%需要的依赖关系。好的做法是首先在根POM的<dependencyManagement/>
部分定义每个项目依赖关系,然后在每个模块POM的<dependencies/>
部分仅指定必需的依赖关系。
此外,你只想在你的实际应用程序(项目D)的文件中只有'spring-boot-maven-plugin',而不是所有的项目,因为它会捆绑每个jar中的所有东西。 –
frezykryger和M. Deinum:谢谢你的建议。我能够解决这个问题,并在下面发布了我的答案。 –