There seems to be an issue with gradle and the implementation of tests. (What kind of error? I have no idea, I didnât program Gradle)
This seems to be some incompatibility or it will be deprecated in the future by Gradle. (Why? no idea)
Letâs start
1 - It shows us this warning
PS E:\Projects\test\.......> ./gradlew build
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
[Incubating] Problems report is available at: file:///E:/Projects/test/......../build/reports/problems/problems-report.html
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.12.1/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD SUCCESSFUL in 27s
We are incubating a potential bug.
Why is it flagging 9.0? I think âGradleâ is doing something new or a viewer or who knows what with the tests.
2 - If we try with --warning-mode all:
PS E:\Projects\test\..........> ./gradlew clean build --warning-mode all
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
> Task :profile-service:test
The automatic loading of test framework implementation dependencies has been deprecated. This is scheduled to be removed in Gradle 9.0. Declare the desired test framework directly on the test suite or explicitly declare the test framework implementation dependencies on the test's runtime classpath. Consult the upgrading guide for further information: https://docs.gradle.org/8.12.1/userguide/upgrading_version_8.html#test_framework_implementation_dependencies
No test executed. This behavior has been deprecated. This will fail with an error in Gradle 9.0. There Test sources are present but no test was executed. Please check your test configuration. Consult the upgrading guide for further information: https://docs.gradle.org/8.12.1/userguide/upgrading_version_8.html#test_task_fail_on_no_test_executed
[Incubating] Problems report is available at: file:///E:/Projects/test/........../build/reports/problems/problems-report.html
BUILD SUCCESSFUL in 23s
We observed âThe automatic loading of test framework implementation dependencies has been deprecated.â
As I said at the beginning, it seems that gradle and junit tests donât go hand in hand or something has happened. Anyone can go to git and look at the history. I donât have time.
3 - If we put the following code in build.gradle.kts to be able to see all the potential problems: In my case spring boot gradle kotlin dsl.
dependencies {
// PARA LOS PERFILES TESTS
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.junit.jupiter:junit-jupiter-api")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testImplementation("com.h2database:h2")
}
tasks.withType<Test> {
useJUnitPlatform()
}
In my case, I had other problems, but the main one is
PS E:\Projects\test\..........> ./gradlew clean build --warning-mode all
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
> Task :profile-service:test
ProfileApplicationTests > contextLoads() FAILED
java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:180
Caused by: org.springframework.beans.factory.BeanCreationException at AutowiredAnnotationBeanPostProcessor.java:515
Caused by: org.springframework.util.PlaceholderResolutionException at PlaceholderResolutionException.java:81
1 test completed, 1 failed
> Task :profile-service:test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':profile-service:test'.
> There were failing tests. See the report at: file:///E:/Projects/test/........../profile-service/build/reports/tests/test/index.html
* Try:
> Run with --scan to get full insights.
BUILD FAILED in 36s
16 actionable tasks: 16 executed
This microservice did not have the tests implemented nor the application.properties, that is why it failed.
A - Datasource error
B - (Solving case 1) MySQL error
If this microservice does not have an application.properties in src/test/java/com/resources/, then it will directly take the path of src\main\resources\application.properties, that is, the official path of your microservice. In my case it is pointing to MySQL (kubernetes) so it does not work.
4 - Create the application.properties in test : (Put âEVERYTHINGâ that your application uses)
your_microservice\src\test\resources\application-test.properties
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update
// In my case I added kafka below because I need it.
Then you use
Conclusion. If we want to disable the warning, we have to put all the tests and especially
tasks.withType<Test> {
systemProperty("spring.profiles.active", "test")
}
Also remember to add the âtestâ annotation since we have called it application-âtestâ.properties
@SpringBootTest
@ActiveProfiles("test")
class ProfileApplicationTests {
@Test
void contextLoads() {
}
}
This is called profiles. You can activate it from application.properties with âspring.profiles.active=testâ. But it is not necessary, since with application-test.properties it is exactly the same. Unless you have different types of tests (very rare).
Note: What you can have in the main are different profiles like âdevâ, âprodâ⊠but in the /src/test/java/com/⊠section you do not have more than one property.
English:Note: It ended up like this:
tasks.withType<Test> {
useJUnitPlatform()
systemProperty("spring.profiles.active", "test")
testLogging {
events("passed", "skipped", "failed")
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
showExceptions = true
showCauses = true
showStackTraces = true
}
}
Solution, you can keep the warning and let âGradleâ update it in the future.
Although by the time Gradle 9.0 arrives all projects will crash. So do what I said if you want to go to the latest version. Thatâs why an error is brewing. Since you have to configure the âtestâ, yes or yes, since it will be mandatory.
Did it work for me? NO. I still get errors. I fix them as they come in to continue the chain of meaningless errors.
This may not be clear at first, but think about it, itâs the only post on the âENTIREâ Internet where it is explained in detail.
My recommendation? Keep the warning. Why? Hopefully they will change it in the future.
Iâm off.