I can do this in the build.gradle
:
println System.getProperty("user.name")
How do I get user ID and primary group ID for current user in a Linux machine?
Capturing the output of exec
is the last thing I want to do.
Gradle doesn't provide such functionality out-of-the-box, however running commands in groovy is fairly easy. Below sample gradle script that does the job:
def username = System.properties['user.name']
println "Username $username"
def uid = ["id", "-u", username].execute().text.trim()
println "UID: $uid"
def gid = ["id", "-g", username].execute().text.trim()
println "GID: $gid"
There is an api for this kind of thing actually
def uid = new com.sun.security.auth.module.UnixSystem().getUid()
How to do it on Windows? I have no idea
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With