Reputation: 7890
I am trying to set several properties in a parent aggregation POM project which are therefore available to all module projects:
<modules>
<module>module1</module>
<module>module2</module>
<module>module3</module>
</modules>
<properties>
<module1.dir>${project.basedir}</module1.dir>
<module1.build.dir>4{project.basedir}/build</module1.build.dir>
</properties>
The properties relate to various directories I intended them to be evaluated relative to the parent POM
I want to refer to the above properties in a second module (module2) like so:
${module1.build.dir}
However when I look at the effective POM of module2, the following expansion results:
<module1.build.dir>_project_root_directory_/module2/build</module1.build.dir>
What I would like is the value of ${module1.dir}
etc. to be expanded relative to the parent POM (where it is defined). Is there anyway to do this in Maven or am I going to have to set some environment variables in a script to do this?
The reason for trying to do this is that I am doing an unusual build in that module1
is a pure native library, module2
is a JNI library that depends on module1
and module3
is a pure Java library that depends directly on module2
.
Upvotes: 2
Views: 852
Reputation: 24192
no, maven does the inheritance 1st (so constructing a leaf pom's effective-pom by combining all of its parents), and only then evaluates properties.
this means properties are always evaluated in the context of the child pom in your case.
this is a requirement for maven to behave properly. look in the super pom and you will see things like:
<build>
<directory>${project.basedir}/target</directory>
...
</build>
which define where sources are looked for and where target classes are written to. they must be evaluated post-inheritance (in the context of a child).
workaround
you could use a property value like ${project.parent.basedir}
, or you could "look sideways" by using ../sibling-module/whatever
. neither of these is pretty.
alternative for maven builds involving native components, have you looked at the maven nar plugin? it was developed for these situations specifically.
Upvotes: 1