2023-09-26 16:31:57 +08:00
2023-09-26 16:29:51 +08:00
2023-01-03 10:28:39 +08:00
2023-09-26 16:29:51 +08:00
2023-09-26 16:29:51 +08:00
2022-01-15 18:46:28 +08:00
2023-01-03 10:28:39 +08:00
2023-09-26 16:29:51 +08:00
2022-08-05 13:18:24 +08:00
2022-08-05 13:18:24 +08:00
2022-01-15 18:46:29 +08:00
2023-09-26 16:31:57 +08:00
2023-09-26 16:29:51 +08:00
2022-09-01 12:38:23 +08:00

Overview

Envelope is a simple Gradle plugin that allows you to create an executable jar file that includes all runtime dependencies and can be executed with a simple

java -jar my-app.jar

It supports JPMS, embedded system properties, Java agents, extra folders to be added to classpath.

Usage

Declare the plugin in your build's settings.gradle like this


pluginManagement {
    repositories {
        maven {
            url = 'https://woggioni.net/mvn/'
        }
    }

    plugins {
        id "net.woggioni.gradle.envelope" version "2023.09.25"
    }
}

Then add it to a project's build.gradle

plugins {
    id 'net.woggioni.gradle.envelope'
}

envelopeJar {
    mainClass = 'your.main.Class'
}

The plugin adds 2 tasks to your project:

  • envelopeJar of type net.woggioni.gradle.envelope.EnvelopeJarTask that creates the executable jar in the project's libraries folder
  • envelopeRun of type org.gradle.api.tasks.JavaExec which launches the jar created by the envelopeJar task

Configuration

EnvelopeJarTask has several properties useful for configuration purposes:

mainClass

This string property sets the class that will be searched for the main method to start the application

mainModule

When this string property is set, the jar file will be started in JPMS mode (if running on Java 9+) and this module will be searched for the main class, if the mainClass is not set the main class specified in the module descriptor will be loaded instead

systemProperties

This is a map that contains Java system properties that will be set before your application starts

extraClasspath

This is a list of strings representing filesystem paths that will be added to the classpath (if running in classpath mode) or to the module path (if running in JPMS mode) when the application starts.

Relative paths and interpolation with Java System properties and environmental variables are supported:

e.g.

This looks for a plugin folder in the user's home directory

${env:HOME}/plugins

Same using Java system properties instead

${sys:user.home}/plugins
javaAgent

This is a method accepting 2 strings, the first is the Java agent classname and the second one is the java agent arguments. It can be invoked multiple times to setup multiple java agents for the same JAR file. All the java agents will be invoked before the application startup.

Example

plugins {
    id 'net.woggioni.gradle.envelope'
}

envelopeJar {
    mainClass = 'your.main.Class'
    mainModule = 'your.main.module'

    systemProperties = [
        'some.property' : 'Some value'
    ]

    extraClasspath = ["plugins"]
    
    javaAgent('your.java.agent.Class', 'optional agent arguments')
}

Limitations

This plugin requires Gradle >= 6.0 and Java >=0 8 to build the executable jar file. The assembled envelope jar requires and Java >= 8 to run, if only mainClass is specified, if both mainModule and mainClass are specified the generated jar file will (try to) run in classpath mode on Java 8 and in JPMS mode on Java > 8.

Description
No description provided
Readme 434 KiB
Languages
Java 100%