Skip to content

hunterwb/AutoManifest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AutoManifest

Automatically generate jar manifest

Keeps the manifest up to date with the build and eliminates unneeded configuration by determining the correct attribute values and creating the manifest at compile time. The attribute names must be passed to javac as a comma separated list: -Aautomanifest=Automatic-Module-Name,Main-Class. If no arguments are given the default is -Aautomanifest=Main-Class. The jar manifest file is created at META-INF/MANIFEST.MF or updated if it already exists. A jar file is not created and the generated manifest file must later be added into the actual jar file, examples below.

Supported attributes:

  • Automatic-Module-Name: The common package of all classes (including package-info.java files). If there is no common package a warning is emitted. This may give bad results if the package structure was not designed with modules in mind.
  • Main-Class: The class containing the main method. If none or multiple are found a warning is emitted.
  • Premain-Class: The class containing the premain method. If none or multiple are found a warning is emitted.
  • Agent-Class or Launcher-Agent-Class: The class containing the agentmain method. If none or multiple are found a warning is emitted.

Supported system property based attributes:

  • Created-By or Build-Jdk: ${java.version} (${java.vendor})
  • Built-By: ${user.name}
  • Build-Jdk-Spec: ${java.specification.version}
  • Build-Os: ${os.name} (${os.version}; ${os.arch})

Any other attribute names on their own will produce a warning. Custom attribute values can be used with any attribute name by including a colon along with the value: Custom-Attribute:custom_value. These values may not contain any commas. Only main attributes are supported, not per-entry attributes.

More information:

Maven usage:
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <annotationProcessorPaths>
                    <path>
                        <groupId>com.hunterwb</groupId>
                        <artifactId>automanifest</artifactId>
                        <version>0.1.0</version>
                    </path>
                </annotationProcessorPaths>
                <showWarnings>true</showWarnings>
                <compilerArgs>
                    <arg>-Aautomanifest=Main-Class,Custom-Attribute:custom_value</arg>
                </compilerArgs>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.2.2</version>
            <configuration>
                <archive>
                    <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>
Gradle usage:
dependencies {
    annotationProcessor 'com.hunterwb:automanifest:0.1.0'
}

compileJava {
    options.compilerArgs.add('-Aautomanifest=Main-Class,Custom-Attribute:custom_value')
}

jar {
    manifest {
        from compileJava.destinationDirectory.file('META-INF/MANIFEST.MF')
    }
}