Warning on using project.parent.version as the version of a module in Maven 3

前端 未结 2 468
轮回少年
轮回少年 2020-12-03 00:07

In maven multi-module projects where I want each of the modules to always keep the same version as the parent, I\'ve typically done something like the following in the modul

2条回答
  •  情话喂你
    2020-12-03 00:57

    I'm curious to know what the real problem with tying a module's version to the parent version is, if any? Or is this a case of a general warning when any expression, regardless of whether it's project.parent.version, is used for the version element.

    Well, that would be easy to test. Because I was curious, I just did it for you using the following pom:

    
      4.0.0
      
        parent
        com.mycompany
        1.0-SNAPSHOT
      
      com.mycompany
      module
      ${myversion}
      module
      http://maven.apache.org
      
        1.0-SNAPSHOT
      
      ...
    
    

    And maven is indeed complaining:

    [WARNING] 'version' contains an expression but should be a constant. @ com.mycompany:module:${myversion}, /home/pascal/Projects/maven-maven3-testcase/module/pom.xml
    

    To be honest, I think that maven is right here, it doesn't make much sense to use a property for the element (at least not for project.version) and it's nice to have maven complaining about it.

    And if you want to use the parent pom version in sub-modules, just remove the tag from the child poms, they will inherit the version from the parent. What you are currently doing is unnecessary.

提交回复
热议问题