How to set a default value to @OutputDirectory outputDir, like "out". And meanwhile allow user to override this default value to be "out2"?

How to set a default value to @OutputDirectory outputDir, like “out”. And meanwhile allow user to override this default value to be “out2”?

Thanks in advance

Just assign a value to the field within in your task class or from the outside if defined by a plugin.

Example:

@OutputDirectory
File outputDir = new File('out')

Using ‘new File(…)’ is not a good idea.

It should be:

@OutputDirectory
File outputDir = project.file('out')

Good point.

Yeah, works perfectly. Thank you, Benjamin and Luke.

Benjamin or Luke,

I assign the default value, and trying to set the default value inside build.gradle. Had a hard time to figure it out.

the way I’m using as below:

build.gradle

myPluginName {
    taskName {
        property = "this is the value to override the default"
    }
}