Adding Resources in a Spring Gradle bootRun task

I'm relying more on Gradle for all of my build and package processes rather than IDE builders and launchers to get closer to the action. In the Spring Boot Wicket web application I'm working on (more on that another time) I would assemble my project outputs as usual in Gradle then watch in fascination as my resources would disappear when I did a bootRun.

What was a structure like this…

the second I launched bootRun looked like this.

I obviously needed to manage how the Spring bootRun Gradle task handled web app resources. I read about the bootRun addResources parameter on the Spring Boot Gradle Plugin guide and how it “removes duplicate resources from target/classes to prevent them to appear twice if ClassLoader.getResources() is called.”

bootRun {
addResources = false
}

I added the parameter as advised but that only broke Gradle, which didn't like the addResources bootRun parameter one bit.

The problem was that the Spring Guide was based on the newest 1.2.2 version of the Spring Boot Gradle Plugin. I was using 1.1.5 or something. I upgraded my Gradle Plugin to 1.2.2 but that still didn't solve the case of the disappearing resources. I had to tell Gradle where they were located.

sourceSets {
main {
output.resourcesDir = "build/resources"
}
}

There, all better!

More Like This Post