我有一个带有模块的 Maven 项目。我的根项目的父项目是 spring-boot-starter-parent
,它提供了大量的依赖管理。
在我的模块中,我使用 spring-boot-configuration-processor
,它是由 spring-boot-starter-parent
管理的依赖项之一(嗯,实际上由其父级 spring-boot-dependency
管理)。
如果我没有在插件部分指定版本,我的构建将失败并显示:
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-dependency
有很多针对各种依赖的版本的属性,但是它没有针对spring-boot-configuration-processor
版本的属性。它也不在插件管理中包含 spring-boot-configuration-processor
。
如何使用此插件的继承版本,而不必自己显式指定版本?
最佳答案
我确实相信而不是配置 maven-compiler-plugin
你只需要声明 spring-boot-configuration-processor
作为项目的依赖项 scope=provided
- annotationProcessorPaths
的目的和annotationProcessors
maven-compiler-plugin
的参数不是添加注释处理器,而是强制编译器仅使用定义的注释处理器。
<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>
关于java - Maven 需要为托管依赖项指定插件版本 spring-boot-configuration-processor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70207686/