【发布时间】:2022-01-09 10:20:06
【问题描述】:
我有一个带有模块的 Maven 项目。我的根项目的父级是spring-boot-starter-parent,它提供了很多依赖管理。
在我的模块中,我使用spring-boot-configuration-processor,它是由spring-boot-starter-parent 管理的依赖项之一(嗯,实际上由其父级spring-boot-dependencies 管理)。
如果我不在插件部分指定版本,我的构建将失败并显示:
Resolution of annotationProcessorPath dependencies failed: For artifact {org.springframework.boot:spring-boot-configuration-processor:null:jar}: The version cannot be empty. -> [Help 1]
所以,我不得不让插件部分看起来像这样:
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>2.6.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
但是,我更愿意引用继承的版本。虽然spring-boot-dependencies对于各种依赖的版本有很多属性,但是对于spring-boot-configuration-processor的版本没有属性。插件管理中也不包含spring-boot-configuration-processor。
如何使用这个插件的继承版本,而不必自己明确指定版本?
【问题讨论】:
-
我不认为你可以。 Maven 允许您继承依赖项和插件的版本,但这是一种特殊情况,因为它是插件的配置。您至少可以利用 spring-boot-configuration-processor 的版本将匹配 spring-boot-starter-parent 的事实,因此您可以将自己的属性
spring.version设置为 2.6.0,然后将其用于他们两个。 -
@Michael 我试过了,但它给出了一个不同的错误:
Non-resolvable parent POM: Could not find artifact org.springframework.boot:spring-boot-starter-parent:pom:${spring.version} in central (https://repo.maven.apache.org/maven2) and 'parent.relativePath' points at no local POM
标签: java spring spring-boot maven