2

I'm noticing that Maven output is reporting plugin version numbers different than what I'm specifying in the pom file.

For example, in my pom I specify the compiler plugin version of 3.1

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.1</version>
</plugin>

But when Maven runs (package, install...whatever) it outputs that it used the version 2.3.2 for the compiler plugin

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

Is there some global maven settings file that trumps local pom file configuration?

Turbo
  • 2,490
  • 4
  • 25
  • 30

3 Answers3

4

Update

Plugin management is a mechanism for sharing default configuration of a plugin (from parent or same project) and it gets overridden by the values in your effective pom build plugins section, so that is not the solution.

It can be that you have a profile in your pom which gets activated and it overrides the plugin version value (see below under debug, read your effective pom). Comment out (<!--, -->) the profile node in your pom and rerun the build if so.

If this is the cause, you can deactivate the profile in your pom or when running from command line just append -P !<PROFILE_NAME> or -P \!<PROFILE_NAME> for linux.

More specifically if your pom looks like this:

<project>
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>someGroupId</groupId>
                    <artifactId>someArtifactId</artifactId>
                    <version>versionFromPluginManagement</version>
            ...
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>someGroupId</groupId>
                <artifactId>someArtifactId</artifactId>
                <version>versionFromPlugins</version>
              ...
    </build>
    <profiles>
        <profile>
            <activation>
                <activeByDefault>BOOLEAN_STRING</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>someGroupId</groupId>
                        <artifactId>someArtifactId</artifactId>
                        <version>versionFromProfile</version>
        ...
  </project>

Artifact someGroupId:someArtifactId is defined in the pluginManagement, plugins, and profiles section. The version resolution goes:

  • if versionFromPlugins isn't defined and BOOLEAN_STRING is false then the resulting version is versionFromPluginManagement
  • if versionFromPlugins is defined and BOOLEAN_STRING is false then the resulting version is versionFromPlugins
  • if BOOLEAN_STRING is true then the resulting version is versionFromProfile

If that is not so, then please run:

mvn help:effective-pom > pom.log
mvn help:effective-settings > settings.log
mvn -version > environment.log

and post contents here.

Original answer

Is there some global maven settings file that trumps local pom file configuration?

Yes, there is. There are at least two of them actually: the global one in the maven installation folder, and the per-user one next to the local repository folder.

When you run maven against your project it interpolates those two files with your pom file, and calculates the resulting one which will be applied when building the project.

Debugging

  • mvn -X clean compile > build.log - run maven with verbose output with -X (debug) command line flag. Since there is a lot of output it is recommended to pipe it (>) to a file. This is especially helpful when using plugins with erroneous documentation as you can see all the plugin properties and their actual values prior to their execution.
  • mvn help:effective-pom > pom.log calculates the pom which will be applied when building your project. It also shows the active profiles.
  • mvn help:effective-settings > settings.log calculates the settings which will be applied when building your project

First examine your effective pom, then debug output and finally the effective settings.

Environment

Rarely, the problem can be in the environment. You must be aware that maven uses java, so you'll need these to know your actual environment:

  • java -version
  • mvn -version

Maven knows its environment by the following environment variables (see its install instructions):

  • M2_HOME - absolute path to maven installation folder root
  • M2 - the bin folder of the above, that's where maven executable is
  • JAVA_HOME -absoulte path to JDK installation folder root - by changing this value you change the Java which Maven uses

Of course, all three variables must be in the PATH environment variable.

Community
  • 1
  • 1
linski
  • 5,046
  • 3
  • 22
  • 35
1

The best thing to define such thing is to use pluginManagement like this:

<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>
    ...
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.1</version>
        </plugin>
      </plugins>
    </pluginManagement>
    ...
  </build>
</project>

This should solve you problem, but I'm not 100% sure, cause i don't have the full pom file.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • the value from pluginMangement gets overriden by the one in the effective pom plugins section for the corresponding plugin, so this is not it (try it) :) – linski Aug 23 '13 at 13:16
  • What do you mean? The plugin itself has no pluginManagement pom. It should be put into your pom file (may be in the parent of your project). – khmarbaise Aug 23 '13 at 13:57
  • If a pom has pluginmanagement (pm) and inside its plugins (ps) it has defined a plugin (p) with group/artifact/version (gav) set, and has a p defined in build.ps and pm.ps.p.g === b.ps.p.g and pm.ps.p.a === b.ps.p.a then b.ps.p.v overrides pm.ps.p.v and not vice-versa. If there is an **active** profile (pr) in the pom with a defined b.ps.p with same g and a then pr.b.ps.p.v overrides the b.ps.p.v. I'm sorry for the abbreviations, wouldn't fit in the comment otherwise. – linski Aug 23 '13 at 14:21
0

It seems that Maven ignores the set version if you run versions:set and package (or whatever the consuming goal is) in the same mvn invocation. But running them in separate invocations works.

In other words, this works (for me at least):

mvn -DnewVersion=0.0.2 versions:set
mvn package

This does not work:

mvn -DnewVersion=0.0.2 versions:set package
chriskilding
  • 829
  • 6
  • 26