-2

I have the use case in which I need to write some properties to the spring boot application.yml file for each Spring boot profile at the maven build time.

Input(application.yml) :

spring:
  profiles: ED

eureka:
  client:
    enabled: true
    availabilityZones:
      us-west-2: us-west-2a,us-west-2b
    serviceUrl:
      us-west-2a: http://regdiscovery:${eureka.environment}@memeboot-regdiscovery1-ed.aord.expertcity.com:8080/eureka/

---
spring:
  profiles: RC

eureka:
  client:
    enabled: true
    availabilityZones:
      us-west-2: us-west-2a,us-west-2b
    serviceUrl:
      us-west-2a: http://regdiscovery:${eureka.environment}@memeboot-regdiscovery1-rc.aord.expertcity.com:8080/eureka/

Expected output(application.yml after maven build):

spring:
  profiles: ED

eureka:
  client:
    enabled: true
    availabilityZones:
      us-west-2: us-west-2a,us-west-2b
    serviceUrl:
      defaultZone: dummy-url-1,dummy-url-2
      us-west-2a: http://regdiscovery:${eureka.environment}@memeboot-regdiscovery1-ed.aord.expertcity.com:8080/eureka/

---
spring:
  profiles: RC

eureka:
  client:
    enabled: true
    availabilityZones:
      us-west-2: us-west-2a,us-west-2b
    serviceUrl:
      defaultZone: dummy-url-1,dummy-url-2
      us-west-2a: http://regdiscovery:${eureka.environment}@memeboot-regdiscovery1-rc.aord.expertcity.com:8080/eureka/ 

Please notice the added line defaultZone: dummy-url-1,dummy-url-2 in the expected output. Is there any maven plugin available to achieve this ?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Piyush Kumar
  • 119
  • 1
  • 7
  • Have you considered defining PATH variables in your environments (test, prod, etc.) and then injecting it in the properties file? For example: defaultZone: ${DEFAULT_ZONE} – Boris Sep 20 '18 at 15:44
  • Actually @Boris I want to add the line itself with placeholders like defaultZone: ${SomeEnv}. – Piyush Kumar Sep 20 '18 at 16:25

1 Answers1

1

Use this answer.

You should install Maven Resources Plugin and instead ${property.key} use @property.key@. Like this:

us-west-2a: @eureka.environment@
Artiow
  • 351
  • 1
  • 9
  • Actually Artiow , i want to add this particular line itself. `defaultZone: dummy-url-1,dummy-url-2` or to be more clear I want to add the line with placeholder like `defaultZone: @eureka.environment@` – Piyush Kumar Sep 20 '18 at 16:24
  • Eventually, I am using maven resource plugin to resolve the placeholders but before that I need to add a line `defaultZone: @eureka.environment@` and then I am resolving the placeholder. – Piyush Kumar Sep 20 '18 at 16:29
  • @Piyush Kumar, you may try to add maven property `dummy-url-1,dummy-url-2` or use JVM argument `-Deureka.client.serviceUrl.defaultZone=dummy-url-1,dummy-url-2`. You might need [maven-site-plugin](http://maven.apache.org/plugins/maven-site-plugin/). – Artiow Sep 21 '18 at 06:23