简体   繁体   English

如何使用配置文件 maven 指定 Spring 引导启动器依赖项的版本?

[英]How can I specify version of Spring Boot starter dependency using profile maven?

I'm working in a Spring boot project which has different ways to connect with database, in dev I connect with it only with postgresql driver, and for qa and prod , I need connect through spring-cloud-gcp-starter-sql-postgresql 'cause we have a cloud environment.我在一个 Spring 启动项目中工作,它有不同的方式连接数据库,在开发中我只使用postgresql驱动程序连接它,对于qaprod ,我需要通过spring-cloud-gcp-starter-sql-postgresql连接因为我们有一个云环境。

So for manage all this possibilities I'm working with profiles in maven which controls my Spring profiles.因此,为了管理所有这些可能性,我正在使用 maven 中的配置文件来控制我的 Spring 配置文件。

But I have a problem starter dependencies of spring cloud which are placed on my profile declaration 'cause they has no version and maven cannot recognize the default version.但是我在我的个人资料声明中放置了 spring 云的启动器依赖项问题,因为它们没有版本,并且 maven 无法识别默认版本。

This is a chunk of my pom with the version error:这是我的 pom 的一部分,带有版本错误: 聚甲醛:

So, how can I solve this problem?那么,我该如何解决这个问题呢?

Is there a way to know which is the default version for starter dependencies and save that information in a variable to be used in profile tag?有没有办法知道哪个是启动器依赖项的默认版本并将该信息保存在要在配置文件标签中使用的变量中?

Any ideas will help a lots.任何想法都会有很大帮助。

Thanks for reading and for you time.感谢您的阅读和您的时间。 Greetings to all祝福大家

You can safely extract dependencyManagement out of your profiles.您可以安全地从您的配置文件中提取dependencyManagement

Reference: dependency-scope参考: 依赖范围

import This scope is only supported on a dependency of type pom in the <dependencyManagement> section.这个scope仅在<dependencyManagement>部分中的 pom 类型的依赖项上受支持。 It indicates the dependency is to be replaced with the effective list of dependencies in the specified POM's <dependencyManagement> section.它表示依赖项将被指定 POM 的<dependencyManagement>部分中的有效依赖项列表替换。 Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of a dependency.由于它们已被替换,因此具有导入 scope 的依赖项实际上并不参与限制依赖项的传递性。

So, you can safely extract dependencyManagement out of your profiles.因此,您可以安全地从您的配置文件中提取 dependencyManagement。

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Greenwich.SR2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <profiles>
        <profile>
            <id>prod</id>
            <activation>
                <activeByDefault>false</activeByDefault>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-gcp-starter</artifactId>
                </dependency>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-gcp-starter-sql-postgresql</artifactId>
                </dependency>
            </dependencies>
        </profile>
        ...
   </profiles>

Or you could provide the resolved versions yourself;或者您可以自己提供已解决的版本; for Greenwich.SR2 that will be 1.1.2.RELEASE ...对于Greenwich.SR2将是1.1.2.RELEASE ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Maven - Spring Boot Starter 的版本 - Maven - version of Spring Boot Starter 在Maven中看不到spring-boot-starter-data-mongodb-active和spring-boot-starter-webflux依赖性 - Dont see spring-boot-starter-data-mongodb-reactive and spring-boot-starter-webflux dependency in maven 在一个简单的 Maven 项目中找不到依赖 spring-boot-starter-security - The dependency spring-boot-starter-security is not found in a simple Maven project Maven和spring-boot:如何在spring-boot:repackage上指定配置文件 - Maven and spring-boot: how to specify profile(s) on spring-boot:repackage Maven spring-boot-starter-security将org.springframework.security限制为3.2.8版本且未使用4.0.2 - Maven spring-boot-starter-security limiting org.springframework.security to version 3.2.8 and not using 4.0.2 Maven 依赖与较旧的 Spring Boot 版本 - Maven dependency with older spring boot version 如何使用 Maven 插件在 Spring Boot 中正确配置 Liquibase,以便我可以使用最新版本运行 diff 命令 - How to properly configure Liquibase in Spring Boot with Maven plugin so that a I can run diff command using latest version 行家! Spring Boot 采用了依赖项目中提到的错误依赖版本 - MAVEN! Spring Boot takes wrong dependency version mentioned in dependency project 仅包含带有 Spring Boot maven 插件的配置文件的源包和依赖项 - Include source package and dependency only for a profile with Spring Boot maven plugin 使用Maven的基于Spring Boot Profile的WAR - Spring boot profile based WAR using maven
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM