michel-kraemer / gradle-download-task

📥 Adds a download task to Gradle that displays progress information
Apache License 2.0
688 stars 84 forks source link

Gradle warns about configuration cache problems of `Verify` #403

Open jansorg opened 4 months ago

jansorg commented 4 months ago

Describe the bug

Using Gradle with configuration cache enabled, I'm seeing these warnings for the Verify task:

- Task `:verifyLspBinary` of type `de.undercouch.gradle.tasks.download.Verify`: cannot serialize Gradle script object references as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.9/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
- Task `:verifyLspBinary` of type `de.undercouch.gradle.tasks.download.Verify`: cannot serialize object of type 'org.gradle.api.internal.project.DefaultProject', a subtype of 'org.gradle.api.Project', as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.9/userguide/configuration_cache.html#config_cache:requirements:disallowed_types

Sample build script

Snippets which may help:

     val verifyLspBinary by registering(Verify::class) {
            algorithm("sha256")
            src(myPath)
            checksum("my checksum")
        }

gradle.properties:


org.gradle.caching=true
org.gradle.configuration-cache=true
org.gradle.configureondemand=true
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
michel-kraemer commented 4 months ago

Thanks for spotting this. I'll look into it ...

michel-kraemer commented 4 months ago

🤔 I'm unable to reproduce this. I've created a new directory and copied the build.gradle.kts file from examples/kotlin/verify and your gradle.properties into it. I then ran gradle verifyFile --configuration-cache two times. The first time it prints Calculating task graph as no cached configuration is available for tasks: verifyFile and the second time it says Reusing configuration cache. Everything seems to work as expected.

I also checked the source code and the Verify class does not keep Project as the error message suggests. It only keeps ProjectLayout which actually can be used with the configuration cache.

You did not say which version of gradle-download-task you're using. Please make sure to use the latest version. If the problem persists, please try to create a minimal reproducing example. That would help a lot. Thanks.

jansorg commented 4 months ago

Thanks! I was also unable to reproduce this with tasks of type Download or Verify. I only managed to reproduced the same or a similar problem with task download of the following snippet, using a doLast {...} block.

Demo repository at https://github.com/jansorg/gradle-download-bug-demo

Output for ./gradlew download:

> Task :download
Download https://httpbin.org/json

FAILURE: Build failed with an exception.

* What went wrong:
Configuration cache problems found in this build.

1 problem was found storing the configuration cache.
- Task `:download` of type `org.gradle.api.DefaultTask`: cannot serialize object of type 'org.gradle.api.internal.project.DefaultProject', a subtype of 'org.gradle.api.Project', as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.9/userguide/configuration_cache.html#config_cache:requirements:disallowed_types

See the complete report at file:///Work/source/download-bug-demo/build/reports/configuration-cache/10to7kfptf6o37lcbk57uncn6/dwksd2tnsgpn78k9y64ku1mq/configuration-cache-report.html

build.gradle.kts:

import de.undercouch.gradle.tasks.download.Download
import de.undercouch.gradle.tasks.download.Verify
import org.gradle.internal.impldep.org.apache.commons.codec.digest.DigestUtils
import org.jetbrains.kotlin.daemon.common.toHexString

plugins {
    kotlin("jvm") version "2.0.0"
    id("de.undercouch.download") version "5.6.0"
}

group = "org.example"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    testImplementation(kotlin("test"))
}

tasks.test {
    useJUnitPlatform()
}

kotlin {
    jvmToolchain(17)
}

allprojects {
    tasks {
        val downloadJson by registering(Download::class) {
            src("https://httpbin.org/json")
            dest(layout.buildDirectory.file("my-file.json"))
        }

        val verifyJson by registering(Verify::class) {
            dependsOn(downloadJson)

            algorithm("sha256")
            src(layout.buildDirectory.file("my-file.json"))
            checksum("bab3dfd2a6c992e4bf589eee05fc9650cc9d6988660b947a7a87b99420d108f9")
        }

        create("download") {
            doLast("download JSON file") {
                download.run {
                    src("https://httpbin.org/json")
                    dest("other.json")
                    onlyIfModified(true)
                }
            }
        }
    }
}
github-actions[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had activity in the last 60 days. It will be closed in two weeks if no further activity occurs. Thank you for your contributions.