Home > other >  How to propagate properties in parent POM to child POM post build
How to propagate properties in parent POM to child POM post build

Time:02-05

Have many shared libraries (jar) that use a common parent POM.

Parent POM has property log4j.version defined as 2.17.1

Child projects A and B have log4j dependency defined with version ${log4j.version}

mvn clean install works fine. But when I look at the generated artifact for projects A or B, their POM still says log4j version in dependencies section as ${log4j.version}. That won't have the desired effect of going with version 2.17.1 if other projects start using library A or B. What is a way to keep the version definition in parent, yet have the child projects specify the version in the built artifact?

And I don't want to add log4j dependency in parent POM because I have few child projects that do not need/use log4j at all. Also, that doesn't solve the problem because even then the child projects after build will not call out the dependency to log4j at all? Probably worse than what I have now

CodePudding user response:

This behavior is expected.

Sub-module's pom-files not built like resources files with the property values resolved. They always refer to the parent-pom.

If you add some module A which is a sub-module (contains <parent> definition) to the project dependency, it will download the parent-pom, like transitive dependency, and will take the property value from the parent pom.

Look at some released pom in maven central (FasterXML Jackson), e.g.

property javax.activation.version defined in parent pom

https://repo1.maven.org/maven2/com/fasterxml/jackson/jackson-bom/2.13.1/jackson-bom-2.13.1.pom

and referenced in child pom

https://repo1.maven.org/maven2/com/fasterxml/jackson/jackson-base/2.13.1/jackson-base-2.13.1.pom

  •  Tags:  
  • Related