Gradle 5.0 requires inputs.dir to exist, but sometimes the class that creates it gets skipped

I have a task (that works with Gradle. 4.x) that wants to collect any class compiled by a custom JavaCompile task. Sometimes that JavaCompile task has no input files and so it is skipped.

This leads to:

A problem was found with the configuration of task ':MyProject:jarGeneratedPluginSource'.
> Directory 'C:\dev\MyProject\build\src-generated-compiled\java' specified for property '$1' does not exist.

The tasks look like this:

    project.task('compileGeneratedPluginSource', type: JavaCompile, dependsOn: project.generatePluginSource ) {
        inputs.dir "${project.myExt.srcGeneratedDir}/java"
        outputs.dir "${project.myExt.srcCompiledDir}/java"
        classpath = project.files()
        source = project.file("${project.myExt.srcGeneratedDir}/java")
        destinationDir = project.file("${project.myExt.srcCompiledDir}/java")
        doFirst {
            println "\n\n*** Making folder for generated source compiled output: $destinationDir\n\n"
            project.mkdir destinationDir

    project.task('jarGeneratedPluginSource', type: Jar, dependsOn: [project.compileGeneratedPluginSource] ) {
        inputs.dir "${project.myExt.srcCompiledDir}/java"
        outputs.file "${project.myExt.srcCompiledDir}/${project.myExt.pluginName}-plugin.jar"
        destinationDir = project.file(project.myExt.srcCompiledDir)
        archiveName = "${project.myExt.jarName}-plugin.jar"
        from( "${project.myExt.srcCompiledDir}/java" )

Task generatePluginSource (not shown) may generate some Java source files from an XML configuration, but depending on that configuration it may not generate any Java source files. I’ve forced it to create the source directory for the JavaCompile task to avoid this same problem for it, but because the JavaCompile task is skipped entirely (NO-SOURCE), even my doFirst block that tries to force the creation of the output folder (destinationDir) is skipped.

What is the right way to solve this?

Hi Scott,

Gradle 5.0 validates the inputs for the runtime API as it does for inputs declared via annotations.
So inputs.dir validates that it is actually a directory and inputs.file is actually an input file.

If you don’t care if the input exists or not, why don’t you use inputs.files?

The other option is to declare the input as optional and use null if the directory does not exist.