Spring 使用 gradle 使用活动配置文件启动 war

Spring boot war with active profile using gradle

我正在使用 Gradle 将我的 spring 引导项目构建到 war 文件中。我想使用不同的配置文件构建不同风格的 war 文件。我的 Gradle 文件

中有以下内容
tasks.register("bootRunDev") {
    group = "application"
    description = "Runs the Spring Boot application with the dev profile"
    doFirst {
        tasks.bootRun.configure {
            systemProperty("spring.profiles.active", "dev")
        }
    }
    finalizedBy("bootRun")
}

tasks.register("bootWarDev") {
    group = "application"
    description = "Runs the Spring Boot application with the dev profile"

    doFirst {
        tasks.withType<JavaExec> {
            systemProperty("spring.profiles.active", "dev")
        }
    }

    finalizedBy("bootWar")
}

./gradlew bootRunDev 命令有效,但我正在努力将其注入 war 文件。有什么想法吗?

编辑

我现在正在尝试将 war 文件 application.properites 替换为

tasks.register("bootWarDev") {
    copySpec {
        from("src/main/resources") {
            filter<ReplaceTokens>(Pair("activeProfiles", "dev"))
            println("run")
        }
    }
}

但这也不起作用

解决了我使用 maven 替换的问题需要使用 Gradle 替换 spring.profiles.active=${activeProfile} 并在 project.properties

中定义这个值