Cannot start gradle built Spring Boot app in IDEA due to classpath configuration limitation
Here is what I am trying to do inside IDEA with my Kotlin based Spring Boot project.
My Spring Boot application uses src/main/resources/application.properties to configure logging properties and JPA properties.
I configured my run configuration to use Run Gradle Task: build in place of the standard IDEA build under Before launch. This is done inside the run configuration dialog. I chose to do this because I want to use the same build regardless of where I am building my app.
I am using Gradle 4.1 configured via the wrapper inside build.gradle. I configured gradle inside IDEA to use the gradle wrapper task configurion.
gradle build uses the following output directories for the build. These are the default gradle build output directories.
- build/classes/kotlin/main for the main class files.
- build/classes/kotlin/test for the test class files.
- build/resources/main for the main resource files. This is where application.properties resides after a build.
I configured my Spring Boot run configuration to use the main module for its classpath. The main module has only one place to configure a path so I did the following inside my main module configuration:
- Selected "Use module compile output path"
- Entered the main class files path above next to Output path
When I start my Spring Boot application via the configured run configuration, start up fails because it cannot find application.properties in the classpath. After thinking through the configuration above, this makes sense because there is no place inside the configuration where build/resources/main is added to the classpath.
The issue below requests a feature to allow additional customization of the classpath that would fix what I describe above. It was originally opened in 2005 but has not seen any traction so far.
https://youtrack.jetbrains.com/issue/IDEA-160167
My current workaround and I don't much care for it is to use Gradle's built in Build inside my run configuration.
Any suggestions on how to get my run configuration to work while using gradle build?
Please sign in to leave a comment.
Please see https://youtrack.jetbrains.com/issue/IDEA-175172.
You can also delegate build and execution to Gradle completely: http://mrhaki.blogspot.ru/2016/11/gradle-goodness-delegate-build-and-run.html.
I just posted the following answer on Stack Overflow in response to a similar question. The key is adding a 3rd module that contains the resource build output paths as a dependency for the main module.
https://stackoverflow.com/a/45759889/931472