Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij spring boot expand processResources in gradle build file to replace properties

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}
like image 765
KneeLess Avatar asked Sep 11 '16 14:09

KneeLess


2 Answers

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.

like image 61
Doron Gold Avatar answered Oct 02 '22 13:10

Doron Gold


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?

like image 45
Julie Avatar answered Oct 02 '22 12:10

Julie