See Stack Overflow question:
Can ${...}
properties appear in the <parent>
section of a POM file?
While Maven's documentation claims that property values "are accessible anywhere within a POM", there are several tags that must be "constant", i.e. you cannot use property values in them. Today (2024/7/21) those restrictions are undocumented and unenforced.
Some restrictions can be discovered by trial-and-error, provided you pay attention to Maven's warnings.
To complicate matters, some properties are allowed in tags that are supposed
to be constant. For instance,
magic CI-friendly version properties
can appear in <version>
and <parent> -> <version>
. There may be other
exceptions as well; I can't find a definitive list of magic properties that
Maven treats differently.
baseline
: bog-standard parent-child project setupname-contains-property
: POM where name depends on a property defined in the same filegroupid-contains-property
: POM where groupId depends on a property defined in the same filegroupid-contains-property-defined-in-parent
: child's groupId depends on a property defined in the parentparent-groupid-contains-property-asymmetric
: child declares parent's groupId using a property; parent has a constant groupIdparent-groupid-contains-property-symmetric
: child declares parent's groupId using a property; parent declares its own groupId the same wayparent-version-contains-property-symmetric
: child declares parent's version using a property; parent declares its own version the same wayparent-version-contains-revision-property-asymmetric
: child declares parent's groupId using the magic${revision}
property; parent has a constant groupIdparent-version-contains-revision-property-symmetric
: child declares parent's groupId using the magic${revision}
property; parent declares its own groupId the same way
Maven expects these tags to be constant:
<parent>
and everything in it<groupId>
,<artifactId>
, and<version>
- maybe others (see Open Questions below)
A few notes about specific examples I think are interesting:
groupid-contains-property
unexpectedly works. Maven issues a warning, but
the effective POM has a groupId with the expanded property.
groupid-contains-property-defined-in-parent
unexpectedly works. Maven
issues a warning, but the effective POM has a groupId with the expanded
property.
parent-groupid-contains-property-asymmetric
fails. This is presumably
expected, but it might be surprising because the child does contain enough
information to fully resolve the parent's groupId.
parent-groupid-contains-property-symmetric
unexpectedly works. When the
groupIds are char-for-char equal before property expansion, Maven seems to
accept it (with a warning). Note that this can produce a broken set of
effective POMs if the parent and child do not agree on the value of the
property.
parent-version-contains-revision-property-symmetric
works but produces
broken effective POMs. Maven issues no warnings in this case, but the
final child POM references parent with version v2.0
while the final parent
POM has version v1.0
.
- Can properties appear in
<repositories>
? (A repo might be needed to find the parent, and the parent might have the value for the property.)