338

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.
Rob Kielty
  • 7,464
  • 7
  • 35
  • 50
Istao
  • 7,015
  • 6
  • 30
  • 39
  • 1
    In Maven 3.5.3, this is now an error. Don't disregard warnings! Thanks to @gavenkoa for the answer on how to find the plugin version. – jwm Mar 23 '18 at 16:04

7 Answers7

430

Add a <version> element after the <plugin> <artifactId> in your pom.xml file. Find the following text:

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

Add the version tag to it:

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

The warning should be resolved.

Regarding this:

'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing

Many people have mentioned why the issue is happening, but fail to suggest a fix. All I needed to do was to go into my POM file for my project, and add the <version> tag as shown above.

To discover the version number, one way is to look in Maven's output after it finishes running. Where you are missing version numbers, Maven will display its default version:

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

Take that version number (as in the 2.3.2 above) and add it to your POM, as shown.

Jay
  • 17,766
  • 32
  • 110
  • 167
Todd
  • 4,309
  • 1
  • 11
  • 2
  • 5
    @JBT don't understand why? maven builds are meant to be stable, so what version one would use should be explicitly defined. That is why maven is asking for it. Like the message says, "It is highly recommended to fix these problems because they threaten the stability of your build." – eis Oct 07 '13 at 06:29
  • 3
    It is a bit of an odd one though as you only get this problem if you have added an entry for the plugin to the project POM file. The effective POM has the version element but you still need to add a version element to the project POM to remove this warning. – oenpelli Oct 30 '13 at 00:44
  • 2
    I'm getting the same warnings as the original question, but my pom.xml does not have any reference to maven-compiler-plugin. What am I missing? Thanks! – Vítor E. Silva Souza Nov 29 '13 at 10:57
  • Thanks, @Todd. I got the same warnings for the `maven-jar-plugin`. I tried to identify which version was used in the log (just as you demonstrated to find the `maven-compiler-plugin`). However, I did not find it in the log. I presume use the latest & test is the best approach? – Kevin Meredith May 01 '14 at 13:19
  • 3
    Did not work for me. The plugin version tag was already there. – Erran Morad May 17 '14 at 07:27
  • 4
    Is 2.3.2 the latest version? How can you tell which one is? Or does it not matter? – Pocketkid2 Jul 22 '15 at 02:16
  • 1
    I look at the [INFO] log like you suggest but it's confusing cause one project will say maven-compiler-plugin:3.1, for example, and another project will say maven-compiler-plugin:2.12.4 version. Why would they differ? – Jeach Oct 27 '15 at 15:33
  • @Jeach because this plugin had different versions over time. Sometimes people don't have time to update it, or sometimes they are afraid that it will stop working and leave old versions there :) – kiedysktos Mar 24 '16 at 14:14
  • the reason it "threatens the stability" is because maybe the newer version will break something in your build. you should allways define versions – Mickey Perlstein Oct 26 '17 at 09:27
  • 1
    The latest version is 3.0.0 – user674669 Sep 18 '18 at 23:13
  • 1
    The latest version is listed here https://github.com/apache/maven-jar-plugin/releases, use that one. And I won't tell you what it is right now because it will be incorrect for the majority of the life of this comment. – William Entriken Jul 05 '19 at 07:55
  • 1
    List of available plugins with version you can find here: https://maven.apache.org/plugins/ – Adam Silenko Aug 09 '19 at 10:40
90

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. Just check docs.

SUPER UPDATE I also use:

$ 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:

$ mvn versions:display-dependency-updates
$ mvn versions:display-plugin-updates     # <-- THIS
gavenkoa
  • 37,355
  • 13
  • 206
  • 248
  • 7
    +1. An alternative and more compact variant: `mvn help:describe -Dplugin=groupId:artifactId` – informatik01 Jan 09 '14 at 13:15
  • 3
    Indeed this did not give a solution but it's valuable content anyway: how indeed can one find the version used/expected. Maybe it would have been worth something to mention placing these plugin-version in a parent-pom using the pluginManagement-tag: http://stackoverflow.com/a/10483284/1023341 – gkephorus Sep 02 '15 at 11:18
15

Maven 3 is more restrictive with the POM-Structure. You have to set versions of Plugins for instance.

With maven 3.1 these warnings may break you build. There are more changes between maven2 and maven3: https://cwiki.apache.org/confluence/display/MAVEN/Maven+3.x+Compatibility+Notes

Christian Kuetbach
  • 15,171
  • 4
  • 37
  • 74
15

get the latest version information from:

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):

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

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

Wolfgang Fahl
  • 12,097
  • 9
  • 75
  • 150
10

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:

parent 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:

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

Patrick Koorevaar
  • 807
  • 12
  • 21
2

It's great answer in here. And I want to add 'Why Add a element in Maven3'.
In Maven 3.x Compatibility Notes

Plugin Metaversion Resolution
Internally, Maven 2.x used the special version markers RELEASE and LATEST to support automatic plugin version resolution. These metaversions were also recognized in the element for a declaration. For the sake of reproducible builds, Maven 3.x no longer supports usage of these metaversions in the 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

Note: Maven 3.0 will issue warnings if you do not specify the version of a plugin.

ohahohah
  • 36
  • 1
  • 3
0

Search "maven-jar-plugin" in pom.xml and add version tag maven version

Shukant
  • 11
  • 3