Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get UID in a maven variable?

I can use the current username in a pom.xml-file with ${user.name}, but is there a way to get the uid (userid)?

I use exec-maven-plugin and add arguments to a execution. I've tried different things (${env.UID}, ${user.id}, $UID), but neither work.

I need it to start a process in docker that writes files to a shared directory. If I don't start with the -u-parameter all files will belong to root.
The configuration is like:

<configuration>
  <executable>docker</executable>
  <arguments>
    <argument>run</argument>
    <argument>-u</argument>
    <argument>$UID</argument>
    <argument>...</argument>
  </arguments>
</configuration>
like image 483
Rainer Jung Avatar asked Aug 22 '16 15:08

Rainer Jung


1 Answers

I intended to write a maven plugin to provide the property user.id but then I did not find a way to get the userid with standard java methods.
There are two projects (Java Native Access, Java Native Interface) to have direct access to native informations, but so far I haven't found a way to get the UID.

I fixed my problem by adding a umask-call in my Dockerfile. I strongly recomend to use a solution that does not requires the user-id within maven.

But working on the issue I created a solution for others that really need this. It takes the user.name-property from the system-properties and then opens the passwd-file to search for the uid. Of course this will only work for unix-like systems and it couples the build directly with your environment, so use this solution wisely (idealy not at all).
To use my solution, add this to your pom.xml:

<plugin>
  <!-- Plugin only works with unix-like environments, please use it wisely! -->
  <groupId>org.rjung.util</groupId>
  <artifactId>user-id-maven-plugin</artifactId>
  <version>1.0</version>
  <executions>
    <execution>
      <goals>
        <goal>user-id</goal>
      </goals>
    </execution>
  </executions>
</plugin>
like image 109
Rainer Jung Avatar answered Sep 16 '22 14:09

Rainer Jung