Table of Contents

About

The Application plugin allows you to:

  • get all applications JARs as well as all of their transitive dependencies
  • add two startup scripts (one for UNIX-like operations systems and one for Windows) to run your application.
  • bundle all this material into a single ZIP or TAR file.

Shortcut of the maven assembly plugin

You don't get the possibility to bundle a JVM. See this page for an example on how to do it in pure gradle: How to bundle a jvm in a Gradle application targeting Windows, Linux or Macos

Example

Basic

plugins {
    id 'java'        
    id 'application' 
}
mainClassName = 'package.mainClass'

where:

StartScript

In kotlin:

  • creating a script
val tabliStartScripts = tasks.register<CreateStartScripts>("tabliStartScripts") {
  outputDir = file("${buildDir}/scripts")
  applicationName = "applicationName"
  mainClassName = "com.example.Main"
  classpath = files(configurations.runtimeClasspath) + files(jar.archiveFileName)
}
/**
 * Bug in windows: The input line is too long because of a big classpath
 */
tasks.withType<CreateStartScripts>{
  (windowsStartScriptGenerator as TemplateBasedScriptGenerator).template = resources.text.fromFile("src/gradle/windowsStartScript.bat")
}

Documentation