0

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.

user2668735
  • 1,048
  • 2
  • 18
  • 30
  • Please show your pom file and the file where you are using the properties...? Why do you need them? Why do you need that in your `application.yml` file? Why do you call the goal of resources plugin? Instead of using the life cycle...? – khmarbaise Nov 09 '22 at 10:25
  • I updated the question with more details to answer your questions. – user2668735 Nov 09 '22 at 10:43
  • First why do you have `${project.parent.basedir}/sample/dataset` this? Is that module part of a multi module build? Apart from that you showing only a very small exerpt of the pom file...which is not really helpful.. – khmarbaise Nov 09 '22 at 11:09
  • BTW: I wasn't aware that spring-boot is an OSGi framework? Can you explain why you are trying to use OSGi???? (plugins?) – khmarbaise Nov 09 '22 at 11:10
  • ${project.parent.basedir}/sample/dataset : it is a common use case to reference a directory outside your module, I think you have no other choice than using maven in order to have a relative path to get the application portable. – user2668735 Nov 09 '22 at 11:24
  • Yes you can transform a Spring Boot application into an OSGI container, I am using Felix framework directly, but this is totally unrelated to the question. – user2668735 Nov 09 '22 at 11:25
  • I found the solution ! We have to use @project.parent.basedir@ inside the pom.xml in properties, strange, but it works fine. – user2668735 Nov 09 '22 at 12:14

0 Answers0