Search code examples
gradlegradle-kotlin-dslgradle-task

Set Gradle custom task inputs and outputs


I am writing a Gradle plugin in Kotlin, adding a custom task.

How do I go about declaring the task's inputs and outputs?


Solution

  • You need to provide getter properties with annotations as follows:

    @get:OutputDirectory
    protected val outputDir by lazy {
        // expression that evaluates to the output directory
    }
    
    @get:InputFiles
    protected val inputFiles by lazy {
        // expression that evaluates to your inputs
    }
    

    Therefore you will have to import these 2 classes at the top of your Kotlin file:

    import org.gradle.api.tasks.InputFiles
    import org.gradle.api.tasks.OutputDirectory