The Spring boot application we are developing doesn’t need Tomcat Dependency as we are deploying the war file in JBOSS server.so we excluded dependency in gradle using the following configuration
compile.exclude module: ‘spring-boot-starter-tomcat’
But during the Build JUnit test cases are failing as we excluded the Tomcat dependency.
Is there any way to include the ‘spring-boot-starter-tomcat’ library only during the test cases execution?(I tried to include the library using testCompile() and testRunTime() feature but it is not working)
Exclusions apply to the configuration specified AND any configuration that extends it. The
testRuntime configurations extend from the
compile configuration, so you will not be able to add a dependency to the test configurations that you have explicitly excluded from the
You could create a configuration, add the dependency, and add it to your test class path, but there is no need to do that extra work. Since you are building a war file, the
providedRuntime configurations already give you ability to add a dependency that is not included in the war. This is built in to Gradle.
If you’re also applying the Spring Boot plugin, you might want to review the modifications it makes so that you don’t get a bootable war if you don’t want that.
The provided solution working as expected