Skip to content

Instantly share code, notes, and snippets.

@macsystems
Created May 3, 2015 10:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macsystems/4eee46225ac9c34417e5 to your computer and use it in GitHub Desktop.
Save macsystems/4eee46225ac9c34417e5 to your computer and use it in GitHub Desktop.
Get Implementation-Version from Jar(s)
/**
* Returns the Version from the Manifest Entry
* @return
*/
String getVersion() {
def files = fileTree(include: ['*.jar'], dir: 'libs')
def latestVersion;
for (File file : files) {
def jar = new JarFile(file);
def mainAttribs = jar.getManifest().getMainAttributes();
def version = mainAttribs.getValue("Implementation-Version");
if (version != null) {
println(jar.getName() + " ->" + version)
if (latestVersion == null) {
latestVersion = version;
} else if (!latestVersion.equals(version)) {
throw new RuntimeException("Version Mismatch :" + jar.getName() + " has Version " + version);
}
}
}
return latestVersion;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment