gradle-docker icon indicating copy to clipboard operation
gradle-docker copied to clipboard

Gradle 7.0 refused to run docker because of undeclared dependency

Open ihchristianto opened this issue 3 years ago • 3 comments

What happened?

Gradle 7.0 refused to build the project because the library does not declare dependencies on other task. If we use Gradle 6.7.1 it was okay. Maybe Gradle becomes stricter. Directory & subproject names have been censored.

Execution optimizations have been disabled for task ':dockerPrepare' to ensure correctness due to the following reasons:
  - Gradle detected a problem with the following location: '*******************'. Reason: Task ':dockerPrepare' uses this output of task ':bootBuildInfo' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '*******************'. Reason: Task ':dockerPrepare' uses this output of task ':bootJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '*******************'. Reason: Task ':dockerPrepare' uses this output of task ':bootJarMainClassName' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '*******************'. Reason: Task ':dockerPrepare' uses this output of task ':compileJava' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '*******************'. Reason: Task ':dockerPrepare' uses this output of task ':compileKotlin' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '*******************'. Reason: Task ':dockerPrepare' uses this output of task ':***************:compileJava' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '*******************'. Reason: Task ':dockerPrepare' uses this output of task ':***************:compileKotlin' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '*******************'. Reason: Task ':dockerPrepare' uses this output of task ':***************:inspectClassesForKotlinIC' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '*******************'. Reason: Task ':dockerPrepare' uses this output of task ':***************:jar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '*******************'. Reason: Task ':dockerPrepare' uses this output of task ':***************:processResources' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '*******************'. Reason: Task ':dockerPrepare' uses this output of task ':**********:compileJava' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '*******************'. Reason: Task ':dockerPrepare' uses this output of task ':**********:compileKotlin' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '*******************'. Reason: Task ':dockerPrepare' uses this output of task ':**********:inspectClassesForKotlinIC' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '*******************'. Reason: Task ':dockerPrepare' uses this output of task ':**********:jar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '*******************'. Reason: Task ':dockerPrepare' uses this output of task ':**********:processResources' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.
  - Gradle detected a problem with the following location: '*******************'. Reason: Task ':dockerPrepare' uses this output of task ':processResources' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.0/userguide/validation_problems.html#implicit_dependency for more details about this problem.

Refer to: https://docs.gradle.org/7.0/release-notes.html Screen Shot 2021-05-04 at 17 43 28

What did you want to happen?

docker command should just run with latest Gradle 7.0 Will try to find workaround for the moment

ihchristianto avatar May 04 '21 09:05 ihchristianto

Fixed by changing plugin files settings in build.gradle.kts & COPY operation path in dockerfile from:

  • build.gradle.kts, note it refer files from the root project dir
docker {
    dependsOn(tasks["build"])
    buildArgs(mapOf(
        Pair("APP_VERSION", "$version"),
        Pair("APP_NAME", rootProject.name)
    ))
    name = "gcr.io/**********/credit:${System.currentTimeMillis() / 1000}"
    files("$projectDir")
}
  • dockerfile
ARG APP_NAME
ARG APP_VERSION
ARG JAR_FILE=build/libs/${APP_NAME}-${APP_VERSION}.jar
COPY ${JAR_FILE} app.jar

Into:

  • build.gradle.kts, note now it refers files from the previous task result
docker {
    dependsOn(tasks["build"])
    buildArgs(mapOf(
        Pair("APP_VERSION", "$version"),
        Pair("APP_NAME", rootProject.name)
    ))
    name = "gcr.io/**********/credit:${System.currentTimeMillis() / 1000}"
    files(tasks.withType<org.springframework.boot.gradle.tasks.bundling.BootJar>{ archiveFile })
}
  • dockerfile
ARG APP_NAME
ARG APP_VERSION
ARG JAR_FILE=${APP_NAME}-${APP_VERSION}.jar
COPY ${JAR_FILE} app.jar

ihchristianto avatar May 04 '21 09:05 ihchristianto

I've tried to remove dependsOn task but the problem still occurs.

I believe Gradle 7.0 doesn't allow us to use projectDir. Maybe because the root project is too dynamic so the task may fail when a certain folder doesn't exist or a task is failed.

So, another solution is to use buildDir instead of projectDir.

build.gradle.kts

docker {
    buildArgs(
        mapOf(
            Pair("APP_VERSION", "$version"),
            Pair("APP_NAME", rootProject.name)
        )
    )
    name = "gcr.io/****/credit:${System.currentTimeMillis() / 1000}"
    files("$buildDir")
}

Dockerfile

ARG APP_NAME
ARG APP_VERSION
ARG JAR_FILE=/libs/${APP_NAME}-${APP_VERSION}.jar
COPY ${JAR_FILE} app.jar

ENTRYPOINT ["java", "-jar", "/app.jar"]

aldoKelvianto avatar May 05 '21 05:05 aldoKelvianto

You can configure tasks dependencies in this way (just change bootJar with the one you want):

tasks.dockerPrepare.configure {
    dependsOn(tasks.bootJar.name)
}

szaffarano avatar Jul 07 '22 14:07 szaffarano