Application Plugin

The Application plugin facilitates creating an executable JVM application. It makes it easy to start the application locally during development, and to package the application as a TAR and/or ZIP including operating system specific start scripts.

examples

// using the application plugin
apply plugin: 'application'
  • You can run the application by executing the run task (type: JavaExec). This will compile the main source set, and launch a new JVM with its classes (along with all runtime dependencies) as the classpath and using the specified main class. You can launch the application in debug mode with gradle run --debug-jvm (see JavaExec.setDebug(boolean)).
// Configure the application main class
mainClassName = 'Main'

using ./gradlew run to run the mainClass

  • If your application requires a specific set of JVM settings or system properties, you can configure the applicationDefaultJvmArgs property. These JVM arguments are applied to the run task and also considered in the generated start scripts of your distribution.
// pass the system properties via applicationDefaultJvmArgs
applicationDefaultJvmArgs = [
        "-Dconfig.file=MY_APP_HOME/conf/config.json"
]
  • customizing start script generation

The application plugin can generate Unix (suitable for Linux, Mac OS X etc.) and Windows start scripts out of the box. The start scripts launch a JVM with the specified settings defined as part of the original build and runtime environment (e.g. JAVA_OPTS env var). The default script templates are based on the same scripts used to launch Gradle itself, that ship as part of a Gradle distribution.

The start scripts are completely customizable. You can refer to the documentation of CreateStartScripts for more details and customization examples.

// Creates start scripts for launching JVM applications
startScripts {
    doLast {
        unixScript.text = unixScript.text.replace('MY_APP_HOME', '\$APP_HOME')
        windowsScript.text = windowsScript.text.replace('MY_APP_HOME', '%~dp0..')

    }
}
//This is for the custom startup script:
  task abcStartScripts(type: CreateStartScripts) {
    mainClassName = "Main"
    classpath = startScripts.classpath
    outputDir = startScripts.outputDir
    applicationName = 'analyzer'
    defaultJvmOpts = ["-Dconfig.file=MY_APP_HOME/conf/config.json
"]        
    abcStartScripts {
        doLast {
            unixScript.text = unixScript.text.replace('MY_APP_HOME', '\$APP_HOME') 
            windowsScript.text = windowsScript.text.replace('MY_APP_HOME', '%~dp0..')
        }
    }
}

results matching ""

    No results matching ""