cdsap / Talaiot

Simple and extensible plugin to track task times in your Gradle Project.
MIT License
589 stars 37 forks source link

Configuration Cache support for Custom Publisher #409

Open anewdroid opened 2 months ago

anewdroid commented 2 months ago

Hi Is the Custom Publisher compatible with Configuration Cache? The CC ticket at https://github.com/cdsap/Talaiot/issues/349 mentions that there was a compatibility issue here

Custom Publishers Custom Publishers defined in the build scripts are not valid anymore. We didn’t test the extension of custom publishers in buildSrc convention folder. The extension with new publishers wrapped in >new plugins is still available.

In Talaiot 2.0, how shoudl we write custom publishers ?

cdsap commented 3 weeks ago

Hi @notsatyarth In Talaiot 2.x we support custom publishers and depending on the logic in them it could be compatible with configuration cache. Given a publisher like:

class CustomPublisher : io.github.cdsap.talaiot.publisher.Publisher {

    override fun publish(report: io.github.cdsap.talaiot.entities.ExecutionReport) {
        println("[CustomPublisher] : Number of tasks = ${report.tasks?.size}")
        println("[CustomPublisher] : Kotlin = ${report.customProperties.buildProperties["kotlin"]}")
        println("[CustomPublisher] : Java = ${report.customProperties.buildProperties["java"]}")
        println("[CustomPublisher] : PID = ${report.customProperties.taskProperties["pid"]}")
    }
}

you can register it with:

talaiot {
    publishers {
        jsonPublisher = true
        customPublishers(CustomPublisher())
    }
}

Executing the first build:

❯ ./gradlew build --configuration-cache
Calculating task graph as configuration cache cannot be reused because file 'build.gradle.kts' has changed.
[CustomPublisher] : Number of tasks = 11
[CustomPublisher] : Kotlin = 1.4
[CustomPublisher] : Java = 8
[CustomPublisher] : PID = 2134

BUILD SUCCESSFUL in 4s
2 actionable tasks: 2 up-to-date
Configuration cache entry stored.

Second build reuses configuration cache:

❯ ./gradlew build --configuration-cache
Reusing configuration cache.
[CustomPublisher] : Number of tasks = 11
[CustomPublisher] : Kotlin = 1.4
[CustomPublisher] : Java = 8
[CustomPublisher] : PID = 2134

BUILD SUCCESSFUL in 4s
2 actionable tasks: 2 up-to-date
Configuration cache entry reused.
anewdroid commented 3 weeks ago

Hi @cdsap , thank you for the reply! with some trial and error , I could conclude that using the gradle logger was preventing the publisher from being serializable. I noticed that the Talaio publishers also use println internally. Is that intentional?