Maven plugin version in pom (seemingly) ignored

前端 未结 3 875

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 pl

相关标签:
3条回答
  • 2021-01-25 04:51

    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.

    0 讨论(0)
  • 2021-01-25 04:51

    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.

    0 讨论(0)
  • 2021-01-25 05:16

    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
    
    0 讨论(0)
提交回复
热议问题