gradle.allprojects { ext.getCurrentVersion = { -> def stdout = new ByteArrayOutputStream() exec { commandLine 'git', 'describe', '--tags' standardOutput = stdout } return stdout.toString().trim().toLowerCase() } } task writeCurrentVersionJava { File versionFile = new File("src/main/java/org/photonvision/PhotonVersion.java") versionFile.delete() versionFile << "package org.photonvision;\n" + "\n" + "/*\n" + " * Autogenerated file! Do not manually edit this file. This version is regenerated\n" + " * any time the publish task is run, or when this file is deleted.\n" + " */\n\n" + "public class PhotonVersion {\n" + String.format(" public static final String versionString = \"%s\";\n", getCurrentVersion()) + "}" } build.dependsOn writeCurrentVersionJava