在Maven 2中,如果未为pom.xml
中使用的每个插件指定版本,它将自动选择最新的插件版本,这非常方便。 但是,在Maven 3中,如果您未明确指定插件版本,它将提示您警告消息。 阅读此“ Maven 3兼容性 ”以获取详细信息。
例如,在Maven 2中,通常,我们使用“ maven-compiler-plugin
”插件而不指定版本,并且该插件100%有效。
//...pom.xml in Maven 2
<build>
<finalName>SpringMVC</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
//...
但是,在Maven 3中,以上声明将提示您以下“ WARNING ”消息:
[INFO] Scanning for projects...
[WARNING] Some problems were encountered while building the effective model
for com.mkyong.common:SpringMVC:war:1.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin
is missing. @ line 55, column 12
[WARNING] It is highly recommended to fix these problems because they threaten
the stability of your build.
[WARNING] For this reason, future Maven versions might no longer support
building such malformed projects.
要修复它,只需指定如下插件版本:
//...pom.xml in Maven 3
<build>
<finalName>SpringMVC</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
如何知道Maven的插件版本是什么?
您可以尝试在http://search.maven.org/上搜索插件,或访问插件网站,例如– Maven编译器插件官方网站 。
参考文献
翻译自: https://mkyong.com/maven/maven-3-need-to-know-the-plugin-version/