我有一個帶有模塊的 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在插件管理中。
如何使用此插件的繼承版本而不必自己明確指定版本?
uj5u.com熱心網友回復:
我確實相信,而不是配置,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>
uj5u.com熱心網友回復:
您需要從父 POM 繼承:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>{YOUR_VERSION}</version>
</parent>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/372277.html
