Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reuse properties from application.properties (Spring Boot) in Maven pom.xml?

I would like to define database url, username, password in one place. Currently I have

application.properties with

spring.datasource.url=....
spring.datasource.username=sa
spring.datasource.password=00

And pom.xml with

  <plugin>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-maven-plugin</artifactId>
    <version>4.1.2</version>
    <configuration>
      <url>....</url>
      <user>sa</user>
      <password>00</password>
    </configuration>
  </plugin>

So probably I need to reuse property values defined in application.properties.

This <password>${spring.datasource.password}</password> doesn't work. Also I tried

 <systemProperties>
    <systemProperty>
      <name>url</name>
      <value>....</value>
    </systemProperty>
    ...
 </systemProperties>

Neither approach is working.

like image 823
ieXcept Avatar asked Dec 14 '25 15:12

ieXcept


1 Answers

You can do the reverse by building a properties file from your pom file. In your properties file you'd use something like:

password=${pom.password}

And your pom file would have something like:

<password>your_db_password</password>

Then at:

mvn clean package

Maven will build your properties file.

Here's a simple tutorial: Add Maven Build Information ...

like image 185
Ollie in PGH Avatar answered Dec 16 '25 06:12

Ollie in PGH



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!