Temp directory for native CLI download


(Wyatt Kennedy) #1

I’m writing a gradle plugin that requires an external CLI. I have logic to check if the program exists in the path already, but when it isn’t found, I want to fetch the exe and unpack it somewhere that the plugin can use it. However, I have no idea where to put it.

When I put it in the projects temp directory ("{project.rootDir}/build") it works fine, but any time that directory gets cleaned, my plugin will download and unpack the CLI again, which I do not want. I would put it in the system temp directly like %TEMP% or %LOCALAPPDATA%, but windows blocks running executables in those directories.

Is there some place I should put a CLI that a gradle plugin will use other than another directory in the project root? I’d rather not inconvenience consumers of the plugin by making them add to their .gitignore (or other VCS equivalent)?

(uklance) #2

You could get the user to provide the directory. Eg:

apply plugin: 'foo.bar.myplugin' 
myPlugin {
   installDir = '/somepath'

Perhaps you could default the installDir to "${rootProject.buildDir}/myplugin" and let the user decide if they want it outside of the project or not

(Schalk Cronjé) #3

Look at what https://ysb33rorg.gitlab.io/grolifant provides you for already doing this, then use something like native/tools as a relative directory (below ~/.gradle)

(Wyatt Kennedy) #4

I believe grolifant will serve this purpose well, minus the sdkman support. Thanks!