http://maven.apache.org/pom.html#Properties says property "values are accessible anywhere within a POM".
Should this read "are accessible in most places within a POM"?
I can specify the version of a dependency no problem like so:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
But what about the version of the project itself like so:
<project xmlns="http://maven.apache.org/POM/4.0.0" ...>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>${myversion}</version>
<properties>
<myversion>8</myversion>
</properties>
<modules>
<module>alpha</module>
<module>beta</module>
</modules>
...
If I try this <version> will not take the value 8. Here I've defined ${myversion} in the pom but the same seems to be the case if I specify -Dmyversion=8 on the command line.
If one of the modules specifies its parent with a hardcoded version number like so:
<parent>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>8</version>
</parent>
When I try to build then when maven comes to look at the module's pom it will say it cannot find the given parent pom with version 8.
However if I hardcode version in the parent to 8 as well, rather than using ${myversion}, then everything works fine.
So it seems to me that property substitution does not happen for the /project/version tag of the parent pom.
Is this the case or is there some other explanation for what I seem to be seeing?
Regards,
/George
of your question: If you don't specify a version there are various different outcomes: a) you will get an error... b) if you have defined the version in the dependency management of the project's parent's pom, then that version is taken. The parent of the project doesn't have to be an enclosing superproject.
mvn scm:checkin -Dincludes=pom. xml -Dmessage="Setting version, preping for release." Then you can perform your release (I recommend the maven-release-plugin), after which you can set your new version and commit it as above. The versions plugin is your friend.
Maven properties are value placeholders, like properties in Ant. Their values are accessible anywhere within a POM by using the notation ${X}, where X is the property. Or they can be used by plugins as default values, for example: In your case you have defined properties as version of java.
Property substitution is not allowed in /project/parent/(groupId|artifactId|version)
or in /project/(groupId|artifactId|version)
by design in Maven 2.x.
So the rules are:
project/version
element.project/parent/version
element of children.${myversion}
property${project.groupId}
and ${project.version}
for inter module dependencies.You'll find an infinite number of threads on this topic on the maven user list (see for example Pom Parent Version Properties) and I'll just say that any attempt to workaround the above rules is wrong and doesn't work.
Version less parent
will be allowed in Maven 3.1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With