355

Since I updated to Maven 3 I get the following warning messages at each build :

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.
4

7 回答 7

449

在文件中添加一个<version>元素。找到以下文本:<plugin> <artifactId>pom.xml

<plugin>
  <artifactId>maven-compiler-plugin</artifactId>

向其中添加版本标签:

<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>2.3.2</version>

警告应该得到解决。

关于这一点:

org.apache.maven.plugins 的“build.plugins.plugin.version”:maven-compiler-plugin 丢失

许多人提到了问题发生的原因,但未能提出解决方案。我需要做的就是进入我的项目的 POM 文件,并添加<version>如上所示的标签。

要发现版本号,一种方法是在 Maven 运行完成后查看它的输出。如果您缺少版本号,Maven 将显示其默认版本:

[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ entities ---

获取该版本号(如上2.3.2所示)并将其添加到您的 POM,如图所示。

于 2011-07-24T00:50:45.223 回答
97

像这样运行:

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

对于没有版本的插件。你得到输出:

名称:Maven WAR 插件
描述:从项目构建 Web 应用程序存档 (WAR) 文件
  输出及其依赖项。
组 ID:org.apache.maven.plugins
工件 ID:maven-war-plugin
版本:2.2
目标前缀:战争

使用输出中显示的版本。

更新如果您想在版本列表中进行选择,请使用http://search.maven.org/http://mvnrepository.com/请注意,您最喜欢的 Java IDE 必须有Maven 包搜索对话框。只需检查文档。

超级更新我也使用:

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

最近我发现如何获取插件(或库)的最新版本,因此不再需要谷歌搜索或访问Maven Central

$ mvn versions:display-dependency-updates
$ mvn versions:display-plugin-updates     # <-- THIS
于 2012-09-25T10:43:18.270 回答
15

Maven 3 对 POM 结构的限制更大。例如,您必须设置插件的版本。

对于 maven 3.1,这些警告可能会破坏您的构建。maven2和maven3的变化比较多:https ://cwiki.apache.org/confluence/display/MAVEN/Maven+3.x+Compatibility+Notes

于 2010-11-08T10:55:32.107 回答
15

从以下位置获取最新版本信息:

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

单击最新版本(或您要使用的版本),您将看到依赖项信息(截至 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>

您可能希望使用版本标签和插件标签的注释。

<!-- 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>

如果您愿意,可以修改您的 pom 以在另一个答案中概述的属性标签中包含版本信息。

于 2017-04-06T10:28:56.773 回答
10

我正在为我的项目使用父 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>

项目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>

另见: https ://www.allthingsdigital.nl/2011/04/10/maven-3-and-the-versions-dilemma/

于 2015-01-22T10:38:44.243 回答
2

这里的答案很好。我想添加“为什么在 Maven3 中添加元素”。
Maven 3.x 中的兼容性说明

插件元版本解析
在内部,Maven 2.x 使用特殊的版本标记 RELEASE 和 LATEST 来支持自动插件版本解析。这些元版本在声明元素中也得到了认可。为了可重现的构建,Maven 3.x 不再支持在 POM 中使用这些元版本。因此,用户将需要用具体版本替换这些元版本的出现。

而且我还在maven-compiler-plugin - 用法中找到

注意:如果您不指定插件的版本,Maven 3.0 将发出警告。

于 2018-01-16T07:10:44.440 回答
0

在 pom.xml 中搜索“maven-jar-plugin”并添加版本标签 maven version

于 2018-06-04T13:49:54.647 回答