3

I'm not able to find out if it is possible to read any data in Spring's application.properties in the pom.xml file.

In my application-dev.properties file, I have an attribute:

google.project.id = 123456789

In my application-test.properties file, I have an attribute:

google.project.id = 987654321

In my application.properties file, I have an attribute. At one point I set it up for DEV at another time for TEST:

spring.profiles.active=dev 

In my pom.xml file, I would like to read this project id according to the configuration in the spring.profiles.active attribute:

<configuration>
  <projectId> PROJECT ID ???</projectId>
  <version>1</version>
</configuration>

Please, could someone help me?

Thank you.

  • This might be similar to https://stackoverflow.com/questions/7144620/reading-properties-file-from-maven-pom-file – Gryphon Aug 13 '20 at 01:25
  • Hello Gryphon. Yes, I know that. My question is whether it is possible to do otherwise? In the POM.xml file read a property that is in the APPLICATION.PROPERTIES file. Thanks for trying to help. – Thiago de Melo Fontana Aug 13 '20 at 12:27
  • 1
    I think prior to your edit you only mentioned the single file (application.properties) to read from, which seems to match usage of the properties-maven-plugin specification in the aforementioned link - e.g. https://www.mojohaus.org/properties-maven-plugin/ However, with reading particular files based on information present in a tertiary file, that may be outside the scope of that plugin. – Gryphon Aug 13 '20 at 14:26
  • 1
    Please refer : https://stackoverflow.com/questions/36703499/using-maven-properties-in-application-properties-in-spring-boot – Dinesh Dontha Aug 14 '20 at 04:43
  • @ThiagodeMeloFontana the answer for your question is one post that Dinesh Dontha send the to you. – noNihongo Apr 09 '21 at 16:40

1 Answers1

3

POM.xml is part of maven project build and has nothing to do with spring.

Spring framework has no idea about pom file.

Vlad Ulshin
  • 482
  • 2
  • 5
  • Hello Vlad. I understand but I know that it is possible to read a property present in the POM.xml file from APPLICATION.PROPERTIES. My question is whether it would be possible to do contrary to what is in this article: https://medium.com/@derrya/maven-profile-spring-boot-properties-a34f2b2bb386 – Thiago de Melo Fontana Aug 13 '20 at 12:31
  • I am not aware of the solution that let you populate pom properties from application.properties file. You probably can use environmental variables to set the same value in pom and application.properties – Vlad Ulshin Aug 13 '20 at 17:04