Maven 3关于build.plugins.plugin.version的警告

本文翻译自:Maven 3 warnings about build.plugins.plugin.version

Since I updated to Maven 3 I get the following warning messages at each build : 自从我更新到Maven 3以来,在每个版本中我都收到以下警告消息:

How can I get rid of these warnings? 我如何摆脱这些警告?

[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for proj:id:jar:3.1
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-javadoc-plugin is missing. @ line 195, column 15
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 204, column 15
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-surefire-plugin is missing. @ line 227, column 15
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-jar-plugin is missing. @ line 215, column 15
[WARNING] 'reporting.plugins.plugin.version' for org.codehaus.mojo:jdepend-maven-plugin is missing. @ line 271, column 15
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.

#1楼

参考:https://stackoom.com/question/HIai/Maven-关于build-plugins-plugin-version的警告


#2楼

Run like: 运行像:

$ mvn help:describe -DartifactId=maven-war-plugin -DgroupId=org.apache.maven.plugins

for plug-in that have no version. 对于没有版本的插件。 You get output: 您得到输出:

Name: Maven WAR Plugin
Description: Builds a Web Application Archive (WAR) file from the project
  output and its dependencies.
Group Id: org.apache.maven.plugins
Artifact Id: maven-war-plugin
Version: 2.2
Goal Prefix: war

Use version that shown in output. 使用输出中显示的版本。

UPDATE If you want to select among list of versions, use http://search.maven.org/ or http://mvnrepository.com/ Note that your favorite Java IDE must have Maven package search dialog . 更新如果要在版本列表中进行选择,请使用http://search.maven.org/http://mvnrepository.com/。请注意,您最喜欢的Java IDE必须具有Maven软件包搜索对话框 Just check docs. 只需检查文档即可。

SUPER UPDATE I also use: 我也使用SUPER UPDATE

$ mvn dependency:tree
$ mvn dependency:list
$ mvn dependency:resolve
$ mvn dependency:resolve-plugins  # <-- THIS

Recently I discover how to get latest version for plug-in (or library) so no longer needs for googling or visiting Maven Central : 最近,我发现了如何获取插件(或库)的最新版本,因此不再需要谷歌搜索或访问Maven Central

$ mvn versions:display-dependency-updates
$ mvn versions:display-plugin-updates     # <-- THIS

#3楼

I'm using a parent pom for my projects and wanted to specify the versions in one place, so I used properties to specify the version: 我正在为项目使用父pom,并希望在一个地方指定版本,因此我使用属性来指定版本:

parent pom: 父pom:

<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
         http://maven.apache.org/xsd/maven-4.0.0.xsd">
    ....
    <properties>
        <maven-compiler-plugin-version>2.3.2</maven-compiler-plugin-version>
    </properties>
    ....
</project>

project pom: pom项目:

<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
         http://maven.apache.org/xsd/maven-4.0.0.xsd">
    ....
    <build>
        <finalName>helloworld</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven-compiler-plugin-version}</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

See also: https://www.allthingsdigital.nl/2011/04/10/maven-3-and-the-versions-dilemma/ 另请参阅: https : //www.allthingsdigital.nl/2011/04/10/maven-3-and-the-versions-dilemma/


#4楼

Maven 3 is more restrictive with the POM-Structure. Maven 3对POM结构的限制更大。 You have to set versions of Plugins for instance. 例如,您必须设置插件的版本。

With maven 3.1 these warnings may break you build. 使用Maven 3.1时,这些警告可能会破坏您的构建。 There are more changes between maven2 and maven3: https://cwiki.apache.org/confluence/display/MAVEN/Maven+3.x+Compatibility+Notes maven2和maven3之间还有更多更改: https ://cwiki.apache.org/confluence/display/MAVEN/Maven+3.x+Compatibility+Notes


#5楼

get the latest version information from: 从以下位置获取最新版本信息:

https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin

click on the latest version (or the one you'd like to use) and you'll see the the dependency info (as of 2019-05 it's 3.8.1): 单击最新版本(或您要使用的版本),您将看到依赖项信息(截至2019-05时为3.8.1):

<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<dependency>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.8.1</version>
</dependency>

you might want to use the version tag and the comment for your plugin tag. 您可能要对插件标签使用version标签和注释。

<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
        <source />
        <target />
    </configuration>
</plugin>

if you like you can modify your pom to have the version information in the properties tag as outlined in another answer. 如果愿意,您可以修改pom以在属性标签中包含版本信息,如另一个答案中所述。


#6楼

It's great answer in here. 这是一个很好的答案。 And I want to add 'Why Add a element in Maven3'. 我想添加“为什么在Maven3中添加元素”。
In Maven 3.x Compatibility Notes Maven 3.x兼容性说明

Plugin Metaversion Resolution 插件转换版本解析
Internally, Maven 2.x used the special version markers RELEASE and LATEST to support automatic plugin version resolution. 在内部,Maven 2.x使用特殊的版本标记RELEASE和LATEST来支持自动插件版本解析。 These metaversions were also recognized in the element for a declaration. 这些metaversions在声明元素中也得到认可。 For the sake of reproducible builds, Maven 3.x no longer supports usage of these metaversions in the POM. 为了可复制的构建,Maven 3.x不再支持在POM中使用这些元转换。 As a result, users will need to replace occurrences of these metaversions with a concrete version. 结果,用户将需要用具体的版本替换这些元版本的出现。

And I also find in maven-compiler-plugin - usage 而且我还在maven-compiler-plugin中找到-用法

Note: Maven 3.0 will issue warnings if you do not specify the version of a plugin. 注意:如果您未指定插件版本,则Maven 3.0将发出警告。