[英]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
驱动程序连接它,对于qa和prod ,我需要通过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.