dam dam - 1 year ago 91
Git Question

Programmatically (Java) retrieving the last Git tag for placing version info in software

I've begun versioning my commits with git tag -a v2.3.4 -m 'some message'
so that I can label my software releases with version numbers (e.g. 2.3.4)

I'd like to have an "about" menu item in the software where a user could display what version they are running.

Is there a way to do this (preferably in Java) so that my app can "know" its version tag in git???

uav uav
Answer Source

Something like

import java.io.*;

public class HelloWorld
    public static void main(String []args) throws IOException
        System.out.println("Hello World");
        String command = "git describe --abbrev=0 --tags";
        Process p = Runtime.getRuntime().exec(command);
        BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line; 
        String text = command + "\n";
        while ((line = input.readLine()) != null)
            text += line;
            System.out.println("Line: " + line);

Maybe check with https://www.tutorialspoint.com/compile_java8_online.php

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download