Aníbal
Aníbal

Reputation: 925

Profile change is not working with gradle in jhipster 7

Changing profiles doesn't work in an app generated with jhipster (v7.3 & 7.4) and gradle. I followed this. When I run from command-line gradlew -Pprod, the app always starts in dev profile:

No active profile set, falling back to default profiles: dev,api-docs

I think something broke in the generators as nobody is providing the spring.profiles.active property. I miss it.replace('#spring.profiles.active#', profiles)} in the profile_prod.gradle file that I saw in previous releases. I added it, now application.yml in build folder contains spring: profiles: active: prod, but the app keeps defaulting to dev.

This is my profile_prod.gradle:

dependencies {
    testImplementation "com.h2database:h2"
}
def profiles = "prod"
if (project.hasProperty("no-liquibase")) {
    profiles += ",no-liquibase"
}
if (project.hasProperty("api-docs")) {
    profiles += ",api-docs"
}
springBoot {
    buildInfo()
}
bootRun {
    args = []
}
processResources {
    println 'I'm running -Pprod!'
    inputs.property('version', version)
    inputs.property('springProfiles', profiles)
    filesMatching("**/application.yml") {
        filter {
            it.replace("#project.version#", version)
        }
    }
}

Upvotes: 0

Views: 546

Answers (1)

Aníbal
Aníbal

Reputation: 925

This seems like a bug, I opened an issue, meanwhile this workaround works:

  1. In profile_prod.gradle, add to the processResources config: filter { it.replace('#spring.profiles.active#', profiles) }

  2. Remove or comment bootstrap.yml file, it has an empty spring.profiles.active that overwrites the previous replacement.

Upvotes: 3

Related Questions