I’m learning to use Gradle by putting together a few simple build scripts as an exercise, and I’d like to put the current machine’s hostname in the JAR manifest. I know I can set manifest properties using the following syntax:
jar {
manifest {
attributes('Build-Host', 'foo')
}
}
What I don’t know, however, is the best way to get the hostname of the current machine. Does Gradle itself provide this to the script somehow? I’ve searched the docs and the user guide but haven’t found anything.
Gradle doesn’t provide a public API for getting the hostname. You’ll have to do it on your own, for example by calling Java’s
InetAddress.localHost.hostName.