Created
May 3, 2015 10:42
-
-
Save macsystems/4eee46225ac9c34417e5 to your computer and use it in GitHub Desktop.
Get Implementation-Version from Jar(s)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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