Custom zip task doesn't executed with "NO-SOURCE" in Kotlin DSL

I am writing a releasing plugin for my projects. One of the tasks I create should pack the output of several projects “distZip” outputs into a single zip file (and does several other activities, such as adding static files, calculating version, generates release notes, ets).

My plugin (tailored for the example) looks like this:

open class SemanticVersionPlugin : Plugin<Project> {

    override fun apply(project: Project) {
        project.tasks.create("release", ReleaseTask::class.java) {
            group = "releasing"
        }
    }
}

My task is:

  open class ReleaseTask : Zip() {

    // This fuction copies the content of the distZip output into this task    
    private fun addProjectResultToRelease(zip: Zip, projectPath: String) {
        logger.quiet("   Adding $projectPath")
        with(zip) {
            val distTaskName = "$projectPath:distZip"
            val task = project.tasks.findByPath(distTaskName) ?: throw GradleException("Task not found: $distTaskName")
            task.outputs.files.filter { it.extension == "zip" }.forEach {
                val srcZip = project.zipTree(it)
                //includeEmptyDirs = false
                from(srcZip) {
                    eachFile {
                        this.path = (this.path.replaceBefore(delimiter = "/", replacement = ""))
                    }
                }
            }
        }
    }

    // Some default value overrides
    init {
        outputs.upToDateWhen { false }
        destinationDirectory.file("_release")
        archiveBaseName.set(project.name)        
    }


    @Suppress("unused")
    @TaskAction
    fun action() {
        val ext = project.extensions["semanticVersion"] as SemanticVersionExtension

        println(dependsOn.joinToString { it.toString() })

        // Iterating through dependencies
        dependsOn.forEach {
            it as String
            println("DEP: $it")
            addProjectResultToRelease(this, it.substringBeforeLast(":"))
        }

        from(project.file("version.txt"))

        super.copy()
    }
}

My intention, that in the build script, one simply add dependencies to all the other projects of which the output should add to:

tasks.withType<ReleaseTask> {
    dependsOn(":core:distZip")
    // Other dependencies
}

My first doubt is whether the init block the right place to set up or override defaults for the task?

My other problem, that when I run this task, I got “NO-SOURCE” message:

> ...
> Task :core:distZip UP-TO-DATE
> Task :release NO-SOURCE

How can I specify that the outputs of the corresponding distZips are the inputs of this task?
Is there a hook to set up at the end of the task configuration? I tried to intercept the dependsOn of the task:

override fun dependsOn(vararg paths: Any?): Task {
    super.dependsOn(*paths)
    println("DO>" + paths.joinToString { it.toString() })

    paths.forEach {
        val t = project.tasks.getByPath(it.toString())
        println(t)
        inputs.files(t.outputs)
    }

    return this
}

This feels incorrect, and even more, this approach didn’t solve the problem of no source. (I tried to override the configure function as well, but it is not called at all.)

I stucked here. (The addProjectResultToRelease function worked well when I used a simple buildSrc class.)

So my questions are:
(1) Is the init block the right place to set up (override) default values?
(2) How can I tell to gradle, that it has sources?

Thanks for the help!

After a few dozens of different approaches, I’ve found a solution. I wasn’t far from the correct implementation with overriding the dependsOn function.

First of all, I switched to version 5.4. It made some of the properties of ZipTask deprecated, but otherwise the upgrade was straightforward.

open class ReleaseTask : Zip() {

    // This function zips out the zip files and removes the root directory    
    private fun addProjectResultToRelease(task: Task) {
        logger.quiet("   Adding ${task.path}")
        task.outputs.files.apply { println(this) }.filter { it.extension == "zip" }.forEach {
            val srcZip = project.zipTree(it)
            includeEmptyDirs = false
            from(srcZip) {
                eachFile {
                    this.path = (this.path.replaceBefore(delimiter = "/", replacement = ""))
                }
            }
        }
    }

    // This overrides calls the unzip function for each dependancy
    override fun dependsOn(vararg paths: Any?): Task {
        super.dependsOn(*paths)

        paths.forEach {
            val t = project.tasks.getByPath(it.toString())
            addProjectResultToRelease(t)
        }

        return this
    }

    // Some refactor was needed for upgrade
    init {
        println("Init")
        outputs.upToDateWhen { false }
        from(project.file("version.txt"))
        destinationDirectory.set(project.file("_release"))
        archiveBaseName.set(project.name)
    }

    // At the moment this function override is needless, but here will come some other 
    // activities later
    override fun copy() {
        val ext = project.extensions["semanticVersion"] as SemanticVersionExtension

        println(archiveFile.get())

        super.copy()
    }
}

I still not completely content with settings in init block. There may be a lifecycle function to override instead, but I missed it.