0

I am writing a plug-in using legacy code (on which I don't have any writing rights) for a spring-boot project, and I need to have access to the manifest file in his final form, as produced by the bootJar task. Sadly, this file seems too be directly written to the jar file, without any intermediate file.

Do you know a way to generate the Manifest file in its final form without unzipping the final jar ?

Teocali
  • 2,725
  • 2
  • 23
  • 39
  • Sorry, I didn't get what you mean by "generate the Manifest file". Do you want to generate a new file, or access the one that is packaged within the jar produced by bootJar task? – romtsn Feb 21 '22 at 08:44
  • second. I know I can access it by unzipping the jar, but I wanted to know if there was another way, maybe more direct, to have it generated. – Teocali Feb 21 '22 at 16:07
  • Hmm, since BootJar extends the Gradle's Jar task, I think you could get the manifest object directly from the task (and also configure it, if necessary) - [here](https://github.com/gradle/gradle/blob/be9973037eb74f208d91b1389851482db7efd34b/subprojects/platform-jvm/src/main/java/org/gradle/jvm/tasks/Jar.java#L163-L165) is the line. I guess it also depends on what do you want to do with the manifest. – romtsn Feb 21 '22 at 16:15
  • I use some legacy code who use the file itself to initialize itself. So I need to write it down on disk. I will take a look to see if I can retrieve the bootJar task in my own code to retrieve the manifest content and write it down. – Teocali Feb 21 '22 at 17:04
  • for sure you can, using `tasks.named("bootJar")` or `tasks.withType()` iirc. You'd need to cast it though, but that should be no problem – romtsn Feb 21 '22 at 21:17

1 Answers1

0

Not sure it helps, and couldn't write it as a comment. I had the same challenge with git, to log the commit id.

build.gradle:

plugins {id 'com.gorylenko.gradle-git-properties'}
gitProperties 

project structure:

build
-classes
-generated
-libs
--x.jar
---com
---META-INF
----MANIFEST.MF
---git.properties
src

...

java:

Properties props = new Properties();
InputStream is = getClass().getClassLoader().getResourceAsStream("git.properties");
props.load(is);
log.info("git props: " + props);

so maybe you can try ..getResourceAsStream("META-INF/MANIFEST.MF");

Now I understood you need the access not from the app, but from the plug-in, but still..

Please let us know if you solved the challenge.

ShaharT
  • 442
  • 5
  • 13