Spring boot classpath includes test sources folder
Answered
I'm curious as to how IntelliJ builds the classpath used in a Spring Boot run configuration. I have a Gradle project that includes some groovy tests. The groovy folder is clearly marked as "test sources" in IntelliJ, but that folder shows up in the classpath when I try to launch the Spring Boot run configuration (debug or run mode). The run configuration fails to start up due to some beans in one of the groovy tests that conflict with one of the standard runtime jars. It seems to me like a test sources folder should not be included in the classpath when launching Spring Boot. Is there a way I can prevent that folder from being added to the classpath?
Please sign in to leave a comment.
Please report at https://youtrack.jetbrains.com/issues/IDEA with a sample project to reproduce. It may be also important what project you are using Gradle based or Maven based.
I should have posted the version of IntelliJ IDEA that I'm using:
IntelliJ IDEA 2019.2.4 (Ultimate Edition)
Build #IU-192.7142.36, built on October 29, 2019
Runtime version: 11.0.4+10-b304.77 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 1981M
Cores: 8
IntelliJ has trouble with our Gradle project structure, probably due to some non-standard file placement done by one of our in-house Gradle plugins. In previous versions of IntelliJ, we were able to work around this by telling IntelliJ not to create separate modules per source set. That feature has been deprecated in IntelliJ 2019.2, so we now see the "duplicate content roots detected" error message when importing Gradle projects. We can safely ignore that error, but to fix the problem I was asking about in this thread, we had to add an entry into the build.gradle file to explicitly tell IntelliJ where our source root is located.