Property fields are properly replaced when building from command line using gradle build
command, however, it's not when using IntelliJ IDEA IDE
.
code in build.gradle
ext {
port = 8086
}
processResources {
filesMatching('application.properties') {
expand(project.properties)
}
}
code in application.properties
server.port = ${port}
When you run a Spring Boot application in IntelliJ by clicking the "Run" button, it starts with the regular java command and no gradle tasks actually run. Therefore, the task processResources
doesn't run.
What you want is to run your project in IntelliJ by invoking the gradle task bootRun
. In IntelliJ's gradle tool window click your project to expand it, then expand Tasks
, expand application
, double-click bootRun
.
You should now see in IntelliJ's console that your application starts just as if you ran it form command line with gradle bootRun
.
EDIT
In case you like to keep the ability of clicking the run/debug button in IntelliJ, you can delegate IDE buid/run actions to gradle by choosing this option under Settings | Build, Exectuion, Deployment | Build Tools | Gradle | Runner.
I have the same problem - really annoying. Best solution I have found so far is to save a run/debug configuration in IntelliJ and then go in an edit the configuration, specifying that the gradle task processResources should be executed before launch.
A related thread: how to skip placeholder value if not supplied in properties file in spring boot?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With