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


(Yong Cheng) #1

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


(Benjamin Muschko) #2

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')

(Luke Daley) #3

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

It should be:

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

(Benjamin Muschko) #4

Good point.


(Yong Cheng) #5

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


(Yong Cheng) #6

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"
    }
}