Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get userid and gid in gradle?

Tags:

gradle

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.

like image 369
biocyberman Avatar asked Jul 31 '16 17:07

biocyberman


2 Answers

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"
like image 165
Opal Avatar answered Nov 02 '22 19:11

Opal


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

like image 21
Erik Martino Avatar answered Nov 02 '22 19:11

Erik Martino