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

Ist*_*tao 306 maven-plugin maven-3 maven

自从我更新到Maven 3后,我在每次构建时收到以下警告消息:

我怎样才能摆脱这些警告?

[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.
Run Code Online (Sandbox Code Playgroud)

小智 389

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

<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
Run Code Online (Sandbox Code Playgroud)

添加版本标记:

<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>2.3.2</version>
Run Code Online (Sandbox Code Playgroud)

应该解决警告.

关于这个:

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 ---
Run Code Online (Sandbox Code Playgroud)

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

  • @JBT不明白为什么?maven构建意味着稳定,因此应该明确定义使用的版本.这就是为什么maven要求它.就像消息中所说,"强烈建议解决这些问题,因为它们会威胁到构建的稳定性." (4认同)
  • 2.3.2最新版本?你怎么知道哪一个?或者没关系? (4认同)
  • 这有点奇怪,因为如果您已将插件的条目添加到项目POM文件中,则只会遇到此问题.有效的POM具有版本元素,但您仍需要向项目POM添加版本元素以删除此警告. (3认同)
  • 我收到与原始问题相同的警告,但我的pom.xml没有对maven-compiler-plugin的任何引用.我错过了什么?谢谢! (2认同)
  • 不适合我.插件版本标签已经存在. (2认同)
  • 此处列出了最新版本 https://github.com/apache/maven-jar-plugin/releases,请使用该版本。我现在不会告诉你它是什么,因为在这篇评论的大部分时间里它都是不正确的。 (2认同)

gav*_*koa 82

运行如下:

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

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

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

使用输出中显示的版本.

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

SUPER UPDATE我还使用:

$ mvn dependency:tree
$ mvn dependency:list
$ mvn dependency:resolve
$ mvn dependency:resolve-plugins  # <-- THIS
Run Code Online (Sandbox Code Playgroud)

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

$ mvn versions:display-dependency-updates
$ mvn versions:display-plugin-updates     # <-- THIS
Run Code Online (Sandbox Code Playgroud)

  • +1.另一种更紧凑的变体:`mvn help:describe -Dplugin = groupId:artifactId` (6认同)
  • 事实上,这并没有提供解决方案,但无论如何它都是有价值的内容:如何找到使用/期望的版本.也许值得一提的是,使用pluginManagement-tag将这些插件版本放在父pom中:http://stackoverflow.com/a/10483284/1023341 (3认同)

Chr*_*ach 13

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

使用maven 3.1,这些警告可能会破坏你的构建.maven2和maven3之间有更多变化:https://cwiki.apache.org/confluence/display/MAVEN/Maven+3.x+Compatibility+Notes


Pat*_*aar 9

我正在为我的项目使用父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>
Run Code Online (Sandbox Code Playgroud)

项目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>
Run Code Online (Sandbox Code Playgroud)

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


Wol*_*ahl 6

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

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>
Run Code Online (Sandbox Code Playgroud)

您可能要对插件标签使用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>
Run Code Online (Sandbox Code Playgroud)

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