[英]Maven requires plugin version to be specified for the managed dependency spring-boot-configuration-processor
I have a maven project with modules.我有一个带有模块的 maven 项目。 The parent for my root project is spring-boot-starter-parent
, which provides a lot of dependency management.我的根项目的父级是spring-boot-starter-parent
,它提供了很多依赖管理。
In my module, I use spring-boot-configuration-processor
, which is one of the dependencies managed by spring-boot-starter-parent
(well, actually managed by its parent, spring-boot-dependencies
).在我的模块中,我使用spring-boot-configuration-processor
,它是spring-boot-starter-parent
管理的依赖项之一(实际上由其父spring-boot-dependencies
管理)。
If I don't specify the version in the plugins section, my build fails with:如果我没有在插件部分指定版本,我的构建将失败,并显示:
Resolution of annotationProcessorPath dependencies failed: For artifact {org.springframework.boot:spring-boot-configuration-processor:null:jar}: The version cannot be empty. -> [Help 1]
So, I am forced to have the plugins section look like this:所以,我不得不让插件部分看起来像这样:
<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>
However, I would prefer to reference the inherited version.但是,我更愿意参考继承的版本。 Although spring-boot-dependencies
has a lot of properties for the versions of various dependencies, it does not have a property for the version of spring-boot-configuration-processor
.虽然spring-boot-dependencies
对于各种依赖的版本有很多属性,但是对于spring-boot-configuration-processor
的版本没有属性。 Nor does it include spring-boot-configuration-processor
in plugin management.它也不在插件管理中包含spring-boot-configuration-processor
。
How do I use the inherited version of this plugin instead of having to explicitly specify the version myself?如何使用此插件的继承版本,而不必自己明确指定版本?
You need to inherit from parent POM:您需要从父 POM 继承:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>{YOUR_VERSION}</version>
</parent>
I do believe instead of configuring maven-compiler-plugin
you just need to declare spring-boot-configuration-processor
as a dependency of your project with scope=provided
- the purpose of annotationProcessorPaths
and annotationProcessors
parameters of maven-compiler-plugin
is not to add annotation processor, but to force the compiler to use defined annotation processors only.我确实相信,而不是配置maven-compiler-plugin
,您只需将spring-boot-configuration-processor
声明为具有scope=provided
的项目的依赖项 - maven-compiler-plugin
的annotationProcessorPaths
和annotationProcessors
参数的目的不是添加注释处理器,但强制编译器仅使用定义的注释处理器。
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
...
</plugins>
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<scope>provided</scope>
</dependency>
...
</dependencies>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.