我有一个maven多模块项目,作为我们其他春季引导应用程序的内部库。例如哈希密码,上传文件到minio,查询ldap等。
我们在这个多模块的项目库中广泛地使用了现有的spring引导工具。
这是一个摘录自图书馆的pom.xml
<?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>de.thd</groupId>
<artifactId>utils</artifactId>
<version>3.4.1</version>
<packaging>pom</packaging>
<modules>
<module>common</module>
<module>email</module>
<module>func</module>
<module>geolocation</module>
<module>hashing</module>
<module>idm</module>
<module>io</module>
<module>ldap</module>
<module>messaging</module>
<module>minio</module>
</modules>
<dependencyManagement>
<dependencies> <!-- The parent should provide all that -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.6.6</version>
<type>pom</type>
<scope>import</scope>
<optional>true</optional>
</dependency>
</dependencies>
</dependencyManagement>
<pluginRepositories>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>我可以通过pom将我需要的模块包含在我们的其他spring引导项目中-例如:
<dependency>
<groupId>de.thd</groupId>
<artifactId>ldap</artifactId>
<version>${thd.utils.version}</version>
</dependency>现在我的问题是:
1.是否有一种方法可以从它的消费应用程序中区分库,或者从外部更好地说明要使用哪个春季引导版本?
在多模块库中,我对spring引导版本进行了硬编码:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.6.6</version>
<type>pom</type>
<scope>import</scope>
<optional>true</optional>
</dependency>2. maven是否聪明到只从spring引导中提取较新的依赖项?例如,如果我的应用程序使用spring 2.6.6,而库是spring 2.6.4,那么我最终会使用spring 2.6.6中的jars吗?
3.有更明智的方法来构建这样的库吗?
发布于 2022-04-07 13:21:37
在pom文件中的外部项目中,在为库添加依赖项时,在库的<exclusions>部分中添加<dependency>部分。
<dependency>
<groupId>de.thd</groupId>
<artifactId>ldap</artifactId>
<version>${thd.utils.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
</exclusion>
</exclusions>
</dependency>这将告诉maven,当带库时,不要单独带来它在<exclusions>部分中列出的依赖项。
https://stackoverflow.com/questions/71782633
复制相似问题