Single responsibility gradle plugin for generating project metadata to jar manifest file.
- Runs
manifest
task afterprocessResources
manifest
task creates manifest file inbuild/resources/main/META-INF/MANIFEST.MF
Add to your build.gradle
:
plugins {
id 'com.coditory.manifest' version '0.2.6'
}
Sample MANIFEST.MF
generated for default configuration:
Manifest-Version: 1.0
Main-Class: com.coditory.Application
Implementation-Title: sample-project
Implementation-Group: com.coditory
Implementation-Version: 0.0.1-SNAPSHOT
Built-By: john.doe
Built-Host: john-pc
Built-Date: 2020-03-25T20:46:59Z
Built-OS: Linux 4.15.0-91-generic amd64
Built-JDK: 12.0.2 AdoptOpenJDK
SCM-Repository: git@github.com:coditory/gradle-manifest-plugin.git
SCM-Branch: refs/heads/master
SCM-Commit-Message: Very important commit
SCM-Commit-Hash: ef2c3dcabf1b0a87a90e098d1a6f0341f0ae1adf
SCM-Commit-Author: John Doe <john.doe@acme.com>
SCM-Commit-Date: 2020-03-24T19:46:03Z
This plugin automatically adds metadata to manifest file after processResources. There is nothing you need to do.
For debug purposes you can run manifest
task with some flags:
# Generates manifest file to build/resources/main/META-INF/MANIFEST.MF
./gradlew manifest
# Generates manifest and prints its content
./gradlew manifest --print
# Generates manifest to src/main/resources/META-INF/MANIFEST.MF
./gradlew manifest --main
To disable or override generated manifest attributes configure the plugin in build.gradle
manifest {
buildAttributes = false
implementationAttributes = true
scmAttributes = false
attributes = [
"Custom-1": "Custom-Value",
"Custom-2": 123
]
}
To generate class path attribute with all compile dependencies prefixed with a custom directory use classpathPrefix
:
manifest {
classpathPrefix = "my-jars"
}
See Java tutorial on Adding Classes and Jars to Jar File's Classpath
Take a look at a gradle-manifest-plugin-sample. You can copy ManifestReader.java (with tests) to you own project.
Reading MANIFEST.MF
is tricky. There can be multiple MANIFEST.MF
files on the classpath that comes from libraries.
To read the correct MANIFEST.MF
you need to filter them. Most often Implementation-Title
is used to find the correct one.