自从我更新到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.
在pom.xml文件中的<plugin> <artifactId>后面添加一个<version>元素。找到以下文本:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
添加版本标签:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
该警告应该得到解决。
关于这个:
“build.plugins.plugin。版本的
org.apache.maven。插件:maven-compiler-plugin缺失
很多人都提到了这个问题发生的原因,但没有提出解决方案。我所需要做的就是进入项目的POM文件,并添加如上所示的<version>标记。
要发现版本号,一种方法是在Maven运行结束后查看它的输出。如果您缺少版本号,Maven将显示其默认版本:
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ entities ---
获取该版本号(如上面的2.3.2所示)并将其添加到POM中,如所示。
运行:
$ 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包搜索对话框。检查一下文件。
超级更新我也使用:
$ 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
我正在为我的项目使用父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/