When I run the following command in my maven module (Spring Boot) :
mvn resource:resource
or even
mvn install -DskipTests
I expect my maven properties variables (declared in the module pom.xml) to be resolved:
- ${project.basedir}: resolved
- ${project.build.directory}: resolved
- ${project.parent.artifactId}: resolved
- ${project.parent.basedir}: NOT resolved (the string '${project.parent.basedir}' is injected in my application.yml)
Maven reacts as this variable do not exist: the property is injected "as it" in the application.yml. As soon as I remove the ".parent" in the key, the variable is resolved. Same behaviour with maven 3.6.0 and 3.8.6.
UPDATE: more info
In my pom I define properties like this:
<properties>
<project.plugins-properties-location>${project.basedir}/src/main/conf/plugins-properties.yml</project.plugins-properties-location>
<project.osgi-directory-path>${project.build.directory}/osgi</project.osgi-directory-path>
<project.persona-project-path>${project.parent.basedir}/sample/dataset</project.persona-project-path>
</properties>
And I used them in my application.yml like this:
application:
osgi-directory-path: "@project.osgi-directory-path@"
plugins-properties-location: "@project.plugins-properties-location@"
dataset-properties:
persona-project-path: "@project.persona-project-path@"
I need to export those properties as default properties. Those properties change depending on maven profile.
And to answer the question to why I use mvn resource, it is because Intellij is not smart enough to do it itself when you run the application directly from the main Application class, inside the IDE. Indeed, as soon as you modify the application.yml, it generates the application.yml in the target WITHOUT maven variables resolved. So, instead of waste time and launch a mvn install
each time I modify the conf, I just launch mvn resource:resource
which regenerates the application.yml in target, with resolved maven properties. And it works, excepted for one variable.
I first though that it was related to the fact I use "project.parent" but it would be strange since ${project.parent.artifactId} is resolved.
Final result :
application:
osgi-directory-path: "/media/.../webapp/target/osgi"
plugins-properties-location: "/media/.../webapp/src/main/conf/plugins-properties.yml"
dataset-properties:
persona-project-path: "${project.parent.basedir}/sample/dataset"
UPDATE
I finally find a solution: use @ inside the pom.xml like this:
<properties>
<project.persona-project-path>@project.parent.basedir@/sample/dataset</project.persona-project-path>
</properties>
If someone could answer why we have to do this I will mark it as answered, I will answer myself otherwise.