9

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.

Opal
  • 81,889
  • 28
  • 189
  • 210
biocyberman
  • 5,675
  • 8
  • 38
  • 50

2 Answers2

14

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"
Opal
  • 81,889
  • 28
  • 189
  • 210
5

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

Erik Martino
  • 4,023
  • 1
  • 19
  • 12