Distribution plugin, how to find directory

I am using the distribution plugin to generate a zip file with the application along with a start script. The application is a programming language interpreter and along with the application itself there is a set of files containing the standard library for my interpreter. I’m including these files in the distribution like so:

distributions {
    main {
        distributionBaseName = 'kap-plain'
        contents {
            from('../array/standard-lib') {
                into 'standard-lib'
            }
        }
    }
}

So far so good. After unzipping the distribution the directory standard-lib can be found in the new directory.

When my interpreter starts, I need to load the files in standard-lib and this is where my problem is. I need to be able to find these files once the program starts.

How can I find the location of the standard library from the application itself? I can see in the generated script that it determines the directory and places it in the variable APP_HOME. This is the value I would like to be able to access, but it’s never passed to the application.

I’ve read the documentation for the distribution plugin and I was unable to find an obvious way to solve this. The documentation refers to the template used to generate the script, but it’s not clear to me where this template can be found or how I can override it.

Of course, I could write my own scripts, but then I’d need to maintain versions for at least Linux, Windows and OSX manually, and I’d like to avoid this.

In such situations I usually modify the generated start scripts after the generation with a simple replace to either set some environment variable from the variable you mentioned or pass it as first argument to the program.