Search code examples
javakotlingradlespring-webfluxtestcontainers

gradle build error: The org.gradle.util.GFileUtils type has been deprecated when building Kotlin Spring WebFlux code


Was following along with Spring + Kotlin = Modern + Reactive + Productive presentation on YouTube! by creating a Kotlin-based Spring Web Flux Reactive app using https://start.spring.io/...

Generated the project using these dependencies (please note the Spring Boot and Java versions, as well):

enter image description here

This generated the build.gradle.kts file:

plugins {
        java
        id("org.springframework.boot") version "3.0.6"
        id("io.spring.dependency-management") version "1.1.0"
        id("org.graalvm.buildtools.native") version "0.9.20"
}

group = "bootiful"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_17

repositories {
        mavenCentral()
}

extra["testcontainersVersion"] = "1.18.1"

dependencies {
        implementation("org.springframework.boot:spring-boot-starter-data-r2dbc")
        implementation("org.springframework.boot:spring-boot-starter-webflux")
        runtimeOnly("org.postgresql:postgresql")
        runtimeOnly("org.postgresql:r2dbc-postgresql")
        testImplementation("org.springframework.boot:spring-boot-starter-test")
        testImplementation("io.projectreactor:reactor-test")
        testImplementation("org.testcontainers:junit-jupiter")
        testImplementation("org.testcontainers:postgresql")
        testImplementation("org.testcontainers:r2dbc")
}

dependencyManagement {
        imports {
                mavenBom("org.testcontainers:testcontainers-bom:${property("testcontainersVersion")}")
        }
}

tasks.withType<Test> {
        useJUnitPlatform()
}

Was getting an error when I tried to build it initially (after downloading & extracting the zip file) using gradle build & ./gradlew build on macOS (both using IntelliJ & command line).

When I cloned the GitHub project that this presentation was based on, I got the same exact error:

Using gradle build (also fails when using the wrapper e.g. ./gradlew build):

KotlinApplicationTests > contextLoads() FAILED
    org.junit.jupiter.api.extension.ParameterResolutionException at ParameterResolutionUtils.java:159
        Caused by: java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:142
            Caused by: org.springframework.beans.factory.BeanCreationException at AbstractAutowireCapableBeanFactory.java:1770
                Caused by: org.springframework.r2dbc.connection.init.UncategorizedScriptException at DatabasePopulator.java:65
                    Caused by: org.springframework.dao.DataAccessResourceFailureException at ConnectionFactoryUtils.java:90
                        Caused by: java.util.concurrent.CompletionException at CompletableFuture.java:315
                            Caused by: java.lang.IllegalStateException at DockerClientProviderStrategy.java:256

Using gradle build --warning-mode=all:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.0.5)

2023-05-12T13:12:54.326-07:00  INFO 50318 --- [           main] bootiful.kotlin.KotlinApplicationTests   : Starting KotlinApplicationTests using Java 20.0.1 with PID 50318 (/Users/pnwlover/nks/bootiful/build/classes/kotlin/test started by pnwlover/ in /Users/pnwlover/nks/bootiful)
2023-05-12T13:12:54.328-07:00  INFO 50318 --- [           main] bootiful.kotlin.KotlinApplicationTests   : No active profile set, falling back to 1 default profile: "default"
2023-05-12T13:12:55.184-07:00  INFO 50318 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data R2DBC repositories in DEFAULT mode.
2023-05-12T13:12:55.378-07:00  INFO 50318 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 187 ms. Found 1 R2DBC repository interfaces.

> Task :compileAotTestJava
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

> Task :test
The org.gradle.util.GFileUtils type has been deprecated. This is scheduled to be removed in Gradle 9.0. Consult the upgrading guide for further information: https://docs.gradle.org/8.1.1/userguide/upgrading_version_7.html#org_gradle_util_reports_deprecations

KotlinApplicationTests > contextLoads() FAILED
    org.junit.jupiter.api.extension.ParameterResolutionException at ParameterResolutionUtils.java:159
        Caused by: java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:142
            Caused by: org.springframework.beans.factory.BeanCreationException at AbstractAutowireCapableBeanFactory.java:1770
                Caused by: org.springframework.r2dbc.connection.init.UncategorizedScriptException at DatabasePopulator.java:65
                    Caused by: org.springframework.dao.DataAccessResourceFailureException at ConnectionFactoryUtils.java:90
                        Caused by: java.util.concurrent.CompletionException at CompletableFuture.java:315
                            Caused by: java.lang.IllegalStateException at DockerClientProviderStrategy.java:256

Gradle, Java & Kotlin versions set in my local system:

 gradle -v

------------------------------------------------------------
Gradle 8.1.1
------------------------------------------------------------

Build time:   2023-04-21 12:31:26 UTC
Revision:     1cf537a851c635c364a4214885f8b9798051175b

Kotlin:       1.8.10
Groovy:       3.0.15
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          20.0.1 (Oracle Corporation 20.0.1+9-29)
OS:           Mac OS X 12.6.5 x86_64
java -version
java version "17.0.6" 2023-01-17 LTS
Java(TM) SE Runtime Environment (build 17.0.6+9-LTS-190)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.6+9-LTS-190, mixed mode, sharing)
❯ kotlinc -version
info: kotlinc-jvm 1.8.21 (JRE 20.0.1+9-29)

Why can't I build this when I do a fresh git clone from the repository?

This is the project I am trying to build:

https://github.com/jamesward/nks/tree/main/bootiful

docker daemon was running, I ran the following command (before I tried building with gradle build and/or ./gradlew build)

docker ps:

output:

CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

Like, I said this also happened when I created a new project from within http://start.spring.io. Is this due to TestContainers? Is there any steps/prerequisites required for TestContainers or any other config to be set?

After running the Unix shell script located here:

https://github.com/jamesward/nks/blob/main/postgres.sh

And then checking the docker daemon:

CONTAINER ID   IMAGE           COMMAND                  CREATED          STATUS          PORTS                    NAMES
d12e7449a853   postgres:13.3   "docker-entrypoint.s…"   36 seconds ago   Up 33 seconds   0.0.0.0:5432->5432/tcp   my-postgres

The Unix shell script's tail end:

PostgreSQL init process complete; ready for start up.

2023-05-15 07:45:20.258 UTC [1] LOG:  starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2023-05-15 07:45:20.258 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2023-05-15 07:45:20.259 UTC [1] LOG:  listening on IPv6 address "::", port 5432
2023-05-15 07:45:20.264 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2023-05-15 07:45:20.272 UTC [66] LOG:  database system was shut down at 2023-05-15 07:45:20 UTC
2023-05-15 07:45:20.285 UTC [1] LOG:  database system is ready to accept connections
^C2023-05-15 08:00:13.887 UTC [1] LOG:  received fast shutdown request
2023-05-15 08:00:13.890 UTC [1] LOG:  aborting any active transactions
2023-05-15 08:00:13.894 UTC [1] LOG:  background worker "logical replication launcher" (PID 72) exited with exit code 1
2023-05-15 08:00:13.894 UTC [67] LOG:  shutting down
2023-05-15 08:00:13.919 UTC [1] LOG:  database system is shut down

When I look inside: ../build/reports/tests/test/index.html:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'r2dbcScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/R2dbcInitializationConfiguration.class]: Failed to execute database script
    at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1770)
    at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598)
    at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520)

Would appreciate it if someone else could try to replicate this issue...

Remember, this doesn't work when I created a project via http://start.spring.io using the same dependencies (see screenshot above) that the presenters in the YouTube presentation video used nor did the author's code work when I did a fresh git clone...


Solution

  • After running ./gradlew build --info, the output was something similar to:

    Caused by: java.lang.IllegalStateException: Could not find a valid Docker environment. Please see logs and check configuration
    at org.testcontainers.dockerclient.DockerClientProviderStrategy.lambda$getFirstValidStrategy$3(DockerClientProviderStrategy.java:158)
    at java.util.Optional.orElseThrow(Optional.java:290)
    at org.testcontainers.dockerclient.DockerClientProviderStrategy.getFirstValidStrategy(DockerClientProviderStrategy.java:150)
    at org.testcontainers.DockerClientFactory.client(DockerClientFactory.java:111)
    

    Fixed this by running this from the command line:

    sudo ln -s $HOME/.docker/run/docker.sock /var/run/docker.sock

    Courtesy of a comment someone answered to this SO post:

    Test Container test cases are failing due to "Could not find a valid Docker environment"

    Now, when I run ./gradlew build:

    2023-05-15T20:07:54.290-07:00  INFO 7818 --- [tainers-r2dbc-0] 🐳 [testcontainers/ryuk:0.3.4]           : Creating container for image: testcontainers/ryuk:0.3.4
        2023-05-15T20:07:55.675-07:00  INFO 7818 --- [tainers-r2dbc-0] 🐳 [testcontainers/ryuk:0.3.4]           : Container testcontainers/ryuk:0.3.4 is starting: bc9d6884bf1fe1cc80d8df0754814059953607456dff07dcde380f128fcf00bd
        2023-05-15T20:07:57.176-07:00  INFO 7818 --- [tainers-r2dbc-0] 🐳 [testcontainers/ryuk:0.3.4]           : Container testcontainers/ryuk:0.3.4 started in PT3.00059S
        2023-05-15T20:07:57.202-07:00  INFO 7818 --- [tainers-r2dbc-0] o.t.utility.RyukResourceReaper           : Ryuk started - will monitor and terminate Testcontainers containers on JVM exit
        2023-05-15T20:07:57.203-07:00  INFO 7818 --- [tainers-r2dbc-0] org.testcontainers.DockerClientFactory   : Checking the system...
        2023-05-15T20:07:57.205-07:00  INFO 7818 --- [tainers-r2dbc-0] org.testcontainers.DockerClientFactory   : ✔︎ Docker server version should be at least 1.6.0
        2023-05-15T20:07:57.207-07:00  INFO 7818 --- [tainers-r2dbc-0] 🐳 [postgres:13.3]                       : Creating container for image: postgres:13.3
        2023-05-15T20:07:57.389-07:00  INFO 7818 --- [tainers-r2dbc-0] 🐳 [postgres:13.3]                       : Container postgres:13.3 is starting: a7af084644cc8f800f51b23ea0e3fab8ea83168f7697c009593262eff34f915c
        2023-05-15T20:08:02.544-07:00  INFO 7818 --- [tainers-r2dbc-0] 🐳 [postgres:13.3]                       : Container postgres:13.3 started in PT5.337754S
        2023-05-15T20:08:03.664-07:00  INFO 7818 --- [    Test worker] bootiful.kotlin.KotlinApplicationTests   : Started KotlinApplicationTests in 18.086 seconds (process running for 22.064)
        Customer(id=1, name=James)
        Customer(id=2, name=Josh)