Is there a way during testing to introduce a property into the Java manifest (or enter the entire manifest)?
We read the value from the manifest (version number), which allows null during testing.
So far, we have tried to put the hard MANIFEST.MF file in our test root, but it did not work.
This is the code we use to read the manifest:
private Attributes getManifest() { URLClassLoader cl = (URLClassLoader) getClass().getClassLoader(); Manifest manifest; try { URL url = cl.findResource("META-INF/MANIFEST.MF"); manifest = new Manifest(url.openStream()); } catch (IOException e) { throw Throwables.propagate(e); } return manifest.getMainAttributes(); }
As a last resort, we will consider the functionality that reads the manifest and scoffs at it, but these are integration tests, and they should be a black box (i.e. we avoid ridicule).
Additional Information: Java 7, running Junit tests in IntelliJ or from Gradle.
Andrew M
source share