gradle-docker
gradle-docker copied to clipboard
Gradle 7.0 refused to run docker because of undeclared dependency
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
What did you want to happen?
docker
command should just run with latest Gradle 7.0
Will try to find workaround for the moment
Fixed by changing plugin files
settings in build.gradle.kts
& COPY
operation path in dockerfile
from:
-
build.gradle.kts
, note it referfiles
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 refersfiles
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
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"]
You can configure tasks dependencies in this way (just change bootJar
with the one you want):
tasks.dockerPrepare.configure {
dependsOn(tasks.bootJar.name)
}