Skip to content

Gradle plugin that generates project metadata to META-INF/MANIFEST.MF

License

Notifications You must be signed in to change notification settings

coditory/gradle-manifest-plugin

Repository files navigation

Manifest Gradle Plugin

Build Coverage Status Gradle Plugin Portal

Single responsibility gradle plugin for generating project metadata to jar manifest file.

  • Runs manifest task after processResources
  • manifest task creates manifest file in build/resources/main/META-INF/MANIFEST.MF

Installing the plugin

Add to your build.gradle:

plugins {
  id 'com.coditory.manifest' version '0.2.6'
}

Generated manifest

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

Usage

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

Overriding generated attributes

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
    ]
}

Generating classpath attribute

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

Reading MANIFEST.MF from project

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.

About

Gradle plugin that generates project metadata to META-INF/MANIFEST.MF

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages