|
| 1 | +# Plugin configuration samples for Gradle |
| 2 | + |
| 3 | +## Minimal config |
| 4 | + |
| 5 | +> :warning: This minimal configuration will not bundle a JRE, so final user will need one in order to run the app. |
| 6 | +
|
| 7 | +### Using your own task |
| 8 | + |
| 9 | +Add next task to your `build.gradle` file: |
| 10 | + |
| 11 | +```groovy |
| 12 | +task packageMyApp(type: io.github.fvarrui.javapackager.gradle.PackageTask, dependsOn: build) { |
| 13 | + mainClass = 'fvarrui.sample.Main' |
| 14 | +} |
| 15 | +``` |
| 16 | + |
| 17 | +And run `gradle packageMyApp`. |
| 18 | + |
| 19 | +### Using default task |
| 20 | + |
| 21 | +Default `package` task is configured using `javapackager` extension so, add next to your `build.gradle` file: |
| 22 | + |
| 23 | +```groovy |
| 24 | +javapackager { |
| 25 | + mainClass = 'fvarrio.sample.Main' |
| 26 | +} |
| 27 | +``` |
| 28 | +And run `gradle package`. |
| 29 | + |
| 30 | +## Bundle with a customized JRE |
| 31 | + |
| 32 | +```groovy |
| 33 | +task packageMyApp(type: io.github.fvarrui.javapackager.gradle.PackageTask, dependsOn: build) { |
| 34 | + mainClass = 'fvarrui.sample.Main' |
| 35 | + bundleJre = true |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +> `customizedJre` is `true` by default, so you don't have to specify it. |
| 40 | +
|
| 41 | +## Bundle with a full JRE |
| 42 | + |
| 43 | +```xml |
| 44 | +task packageMyApp(type: io.github.fvarrui.javapackager.gradle.PackageTask, dependsOn: build) { |
| 45 | + mainClass = 'fvarrui.sample.Main' |
| 46 | + bundleJre = true |
| 47 | + customizedJre = false |
| 48 | +} |
| 49 | +``` |
| 50 | + |
| 51 | +## Bundle with an existing JRE |
| 52 | + |
| 53 | +```groovy |
| 54 | +task packageMyApp(type: io.github.fvarrui.javapackager.gradle.PackageTask, dependsOn: build) { |
| 55 | + mainClass = 'fvarrui.sample.Main' |
| 56 | + bundleJre = true |
| 57 | + jrePath = file('C:\Program Files\Java\jre1.8.0_231') |
| 58 | +} |
| 59 | +``` |
| 60 | + |
| 61 | +## Bundle your own fat JAR |
| 62 | + |
| 63 | +```groovy |
| 64 | +task packageMyApp(type: io.github.fvarrui.javapackager.gradle.PackageTask, dependsOn: build) { |
| 65 | + mainClass = 'fvarrui.sample.Main' |
| 66 | + bundleJre = true |
| 67 | + runnableJar = file('path/to/your/own/fat.jar') |
| 68 | + copyDependencies = false |
| 69 | +} |
| 70 | +``` |
| 71 | + |
| 72 | +## Multiple executions |
| 73 | + |
| 74 | +```groovy |
| 75 | +javapackager { |
| 76 | + // common configuration |
| 77 | + mainClass = 'fvarrui.sample.Main' |
| 78 | +} |
| 79 | +task packageMyAppWithJRE(type: io.github.fvarrui.javapackager.gradle.PackageTask, dependsOn: build) { |
| 80 | + name = 'Sample' |
| 81 | + bundleJre = true |
| 82 | +} |
| 83 | +task packageMyAppWithoutJRE(type: io.github.fvarrui.javapackager.gradle.PackageTask, dependsOn: build) { |
| 84 | + name = 'Sample-nojre' |
| 85 | + bundleJre = false |
| 86 | +} |
| 87 | +task packageMyApp(dependsOn: [ 'packageMyAppWithJRE', 'packageMyAppWithoutJRE' ]) |
| 88 | +``` |
| 89 | + |
| 90 | +E.g. on Windows, last configuration will generate next artifacts: |
| 91 | +* `Sample_x.y.z.exe` with a bundled JRE. |
| 92 | +* `Sample-nojre_x.y.z.exe` without JRE. |
| 93 | + |
| 94 | +## Bundling for multiple platforms |
| 95 | + |
| 96 | +```groovy |
| 97 | +javapackager { |
| 98 | + // common configuration |
| 99 | + mainClass = 'fvarrui.sample.Main' |
| 100 | + bundleJre = true |
| 101 | + generateInstaller = false |
| 102 | +} |
| 103 | +task packageMyAppForLinux(type: io.github.fvarrui.javapackager.gradle.PackageTask, dependsOn: build) { |
| 104 | + platform = linux |
| 105 | + createTarball = true |
| 106 | + jdkPath = file('X:\\path\to\linux\jdk') |
| 107 | +} |
| 108 | +task packageMyAppForMac(type: io.github.fvarrui.javapackager.gradle.PackageTask, dependsOn: build) { |
| 109 | + platform = mac |
| 110 | + createTarball = true |
| 111 | + jdkPath = file('X:\\path\to\mac\jdk') |
| 112 | +} |
| 113 | +task packageMyAppForWindows(type: io.github.fvarrui.javapackager.gradle.PackageTask, dependsOn: build) { |
| 114 | + platform = windows |
| 115 | + createZipball = true |
| 116 | +} |
| 117 | +task packageMyApp(dependsOn: [ 'packageMyAppForLinux', 'packageMyAppForMac', 'packageMyAppForWindows' ]) |
| 118 | +``` |
| 119 | + |
| 120 | +E.g. on Windows, running `packageMyApp` task will generate next artifacts: |
| 121 | + |
| 122 | +* `${name}_${version}-linux.tar.gz` with the GNU/Linux application including a customized JRE. |
| 123 | +* `${name}_${version}-mac.tar.gz` with the Mac OS X application including a customized JRE. |
| 124 | +* `${name}_${version}-windows.zip` with the Windows application including a customized JRE. |
| 125 | + |
| 126 | +As last sample is running on Windows, it's not necessary to specify a JDK when bundling for Windows (it uses current JDK by default). Otherwise, if running on GNU/Linux or Mac OS X, you have to specify a JDK for Windows. |
0 commit comments