How can I update a property in a Maven POM?

后端 未结 7 639
耶瑟儿~
耶瑟儿~ 2020-12-13 18:23

I have two top-level Maven projects, backend and frontend, that advance versions at their own individual pace. Since each has multiple modules, I d

7条回答
  •  失恋的感觉
    2020-12-13 19:01

    How to update property in existing POM:

    Try to use filtering in maven-resource-plugin:

    1. specify version in property file;
    2. add custom filter with path to this file (in child pom.xml, where dependency should be injected);
    3. update version in property file;
    4. run build.

    Advantages:

    • it should work;
    • version is specified only once;
    • property file could be added under version control;
    • process-resources is one of the first maven lifecycle steps.

    Disadvantages:

    • well, pom.xml still uses placeholder;
    • additional work to automatically update property file from initial build (too complicated, I suppose there should be easier solutions).

    How to provide propery on build time:

    You could specify any property by build parameter.

    For example, I have property in my pom.xml like:

    
        TODAY
    
    

    To change it during build I simply use parameter:

    mvn compile -Dbuild.date=10.10.2010
    

    I'm pretty sure it will work for version as well. Also, properties from top level projects are inherited by childs.

提交回复
热议问题