我有一个用于 Spring Boot 项目的 Maven POM。POM 导入 Spring Boot BOM。现在我想自定义一个 Maven 插件的配置,比如mvn-compiler-plugin
. 我想使用BOMmaven-compiler-plugin.version
规定的插件版本。spring-boot-dependencies
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ch.ge.mygroup</groupId>
<artifactId>myartifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<spring-boot.version>2.4.2</spring-boot.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- Spring Boot BOM -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<!-- some particular config here -->
</configuration>
</plugin>
</plugins>
</build>
</project>
但这确实有效:我想出了一个 Maven 错误:
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin must be a valid version but is '${maven-compiler-plugin.version}'. @ line 31, column 26
所以我必须明确指定我想要避免的 Maven 插件的版本。
总之:
使用
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<!-- some particular config here -->
</configuration>
</plugin>
产生一个 Maven 错误。
使用
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<!-- some particular config here -->
</configuration>
</plugin>
有效,但阻止我使用 Spring Boot BOM 规定的版本(3.8.1)。
使用
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!-- some particular config here -->
</configuration>
</plugin>
工作,但使用插件的旧版本(3.1)。
如何避免显式指定插件版本,而是隐式使用 Spring Boot BOM 中提供的插件版本?