Read Specification-Version from MANIFEST.MF

Hello, I would like to know, how to read Specification-Version from MANIFEST.MF in Kotlin.

I have tried the Kotlin way and also tried using the following Java class in Kotlin, but no success.

In Java I’m doing the following:

  1. Part of build.gradle

jar {
manifest {
attributes ‘Main-Class’: ‘Application’
attributes ‘Class-Path’: configurations.runtimeClasspath.files.collect { ‘lib/’ + it.getName() }.join(’ ')
attributes ‘Specification-Title’: ‘project name’
attributes ‘Specification-Version’: ‘1.1’
}
}

  1. Project.java

package application;

import java.nio.file.Paths;

public class Project {

String projPath = "";
String projName = "<name>";
String projVersion = "<version>";

public Project() {

	String[] splitPath = null;
	
	try {
	    Package pkg = Main.class.getPackage();
	    
	    if (pkg.getSpecificationTitle() == null) {
			// Project name and version from directory name
	    	projPath = Paths.get(System.getProperty("user.dir")).getFileName().toString();
			splitPath = projPath.split("_");
			projName = splitPath[0];
			projVersion = "v" + splitPath[1] + "." + splitPath[2] + "." + splitPath[3];
	    } else {
	    	// Project name and version from MANIFEST.MF
	    	projName = pkg.getSpecificationTitle();
	    	projVersion = "v" + pkg.getSpecificationVersion();
	    }
	} catch (Exception e) {}
}

public String getPath() {

	return projPath;
}

public String getName() {

	return projName;
}

public String getVersion() {

	return projVersion;
}

}