Hi,

we are using the latest spring boot version (3.2.5).

If a gradle project has the java-test-fixtures gradle plugin activated, resource files are found in tests twice in the classpath. With the jar:file: prefix and a second time with the file: prefix. In the production code, however, the resources are only found once (with the file: prefix).

This encountered when updgrading the kotlin gradle plugin from 1.9.10 to 1.9.20+.

The problem occurs only in combination with java-test-fixtures gradle plugin and Spring Boot.

In our case, this leads to exceptions in the test execution (Flyway finds migrations twice, GraphQL Java Tools scans the schema twice).

You can find a minimal reproduction based on the Spring Boot Multi Module example project here: https://github.com/philib/gs-multi-module (see commit: https://github.com/philib/gs-multi-module/commit/48cc6123b3aa7a7d4133ef58c68e928cceec3f84)

The reproduction consists of 4 gradle modules:

  • application: spring boot application that imports the problematic library and its test fixtures.
  • library that reproduces the issue: libraryWithTestFixturesAndNewKotlinVersion
  • library with old kotlin version: libraryWithTestFixturesAndOldKotlinVersion
  • library with new kotlin version and without testFixtures: libraryWithoutTestFixturesAndNewKotlinVersion
  • library with old kotlin version and without testFixtures: libraryWithoutTestFixturesAndOldKotlinVersion

The following table shows which paths are found in the corresponding test classpath.

gradle project kotlin version testFixtures found resource pathes
libraryWithTestFixturesAndNewKotlinVersion 1.9.20 activated file:, jar:file:
libraryWithTestFixturesAndOldKotlinVersion 1.9.10 activated jar:file:
libraryWithoutTestFixturesAndNewKotlinVersion 1.9.20 deactivated file:
libraryWithoutTestFixturesAndOldKotlinVersion 1.9.10 deactivated file:

Running the spring boot application works fine, but tests fail for the modules applications and libraryWithTestFixturesAndNewKotlinVersion.

We also posted this issues in Jetbrains issue tracker: https://youtrack.jetbrains.com/issue/KT-68278/Spring-resource-loading-in-combination-with-java-test-fixtures-plugin-broken

Do you have any idea why this might be? Many thanks in advance!

Comment From: wilkinsona

Given that the problem only occurs when using the newer version of Kotlin's Gradle plugin, I think it's reasonable to conclude that it's a bug in Kotlin's Gradle plugin.

If you compare the classpaths of the test tasks in libraryWithTestFixturesAndNewKotlinVersion and libraryWithTestFixturesAndOldKotlinVersion you'll see that the former contains both directories and jar files for the project's main code and test fixtures whereas the latter only contains the jar files:

New Kotlin version:

gs-multi-module/initial/libraryWithTestFixturesAndNewKotlinVersion/build/classes/java/test
gs-multi-module/initial/libraryWithTestFixturesAndNewKotlinVersion/build/classes/kotlin/test
gs-multi-module/initial/libraryWithTestFixturesAndNewKotlinVersion/build/resources/test
gs-multi-module/initial/libraryWithTestFixturesAndNewKotlinVersion/build/classes/kotlin/testFixtures
gs-multi-module/initial/libraryWithTestFixturesAndNewKotlinVersion/build/classes/kotlin/main
gs-multi-module/initial/libraryWithTestFixturesAndNewKotlinVersion/build/classes/java/main
gs-multi-module/initial/libraryWithTestFixturesAndNewKotlinVersion/build/resources/main
gs-multi-module/initial/libraryWithTestFixturesAndNewKotlinVersion/build/classes/java/testFixtures
gs-multi-module/initial/libraryWithTestFixturesAndNewKotlinVersion/build/resources/testFixtures
gs-multi-module/initial/libraryWithTestFixturesAndNewKotlinVersion/build/libs/libraryWithTestFixturesAndNewKotlinVersion-0.0.1-SNAPSHOT-test-fixtures.jar
gs-multi-module/initial/libraryWithTestFixturesAndNewKotlinVersion/build/libs/libraryWithTestFixturesAndNewKotlinVersion-0.0.1-SNAPSHOT-plain.jar
…

Old Kotlin version:

gs-multi-module/initial/libraryWithTestFixturesAndOldKotlinVersion/build/classes/java/test
gs-multi-module/initial/libraryWithTestFixturesAndOldKotlinVersion/build/classes/kotlin/test
gs-multi-module/initial/libraryWithTestFixturesAndOldKotlinVersion/build/resources/test
gs-multi-module/initial/libraryWithTestFixturesAndOldKotlinVersion/build/libs/libraryWithTestFixturesAndOldKotlinVersion-0.0.1-SNAPSHOT-test-fixtures.jar
gs-multi-module/initial/libraryWithTestFixturesAndOldKotlinVersion/build/libs/libraryWithTestFixturesAndOldKotlinVersion-0.0.1-SNAPSHOT-plain.jar

The latter is correct as it isn't duplicating the same classes and resources in two different locations on the classpath.