Maven: modifying manifest JAR manifest files

any help or pointers would be greatly appreciated. I need to enter two fields in the manifest file of all the dependency JAR modules of my project at build time.

Dependency tanks are already being built and retrieved from the repo. I need to find a way to get the JAR manifest file and then modify it using the variables in my current pom file. Has anyone done this before to know how to do this. Thank you in advance for your time and reply.

+6
source share
2 answers

This is not what Maven allows you to do. From Maven's point of view, every JAR with a specific name should be exactly the same as every other JAR with the same name.

For example, let my project depend on abc-1.0.jar . I indicate this dependency because the ALphabet team published the abc library with the specified API for version 1.0. I should be able to get this jar file from any repository in the world, even from my street neighbor, when my Internet goes out and manually installs it in my local repository, and it should be exactly the same file. If it were not the same file, then I would not have a guarantee that the .class files inside the jar will contain the library code that I need to make my build successful without errors.

If you are truly motivated to do this job, it is theoretically possible. You can write a script that will:

  • Parse the POM XML for the properties section and parse the individual properties from there, as well as the names of the dependency jars
  • For each dependency ban with the "manifest_injected" classifier, try to find it in the local repository. If it does not exist, generate an empty Maven project with the given dependencies (without the manifest_injected classifier), run mvn validate on it to make sure that the dependencies are loaded and placed in the local repository if they were found
  • Clone all specified JAR files, open clones, inject the manifest that you need with the properties you previously analyzed and save the entered jars to the right places in the Maven repository.
  • Call the Maven assembly that was passed to the script as an argument.

Good luck

0
source

You can do this easily in your binary repository. For example, Artifactory allows you to write a custom plugin that will run on any load . In this listener, you can write your own code - open the bank, change the manifest and transfer the changed bank instead of the original (and cache it next time).

0
source

Source: https://habr.com/ru/post/950261/


All Articles