Skip to content

Commit 3bb6960

Browse files
committed
A gradle configuration samples
1 parent 1da034b commit 3bb6960

File tree

3 files changed

+192
-5
lines changed

3 files changed

+192
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Add the following `plugin` tag to your `pom.xml`:
4747
</plugin>
4848
```
4949

50-
> See [Maven plugin configuration samples](docs/maven-plugin-configuration-samples.md) to know more.
50+
> See [Maven plugin configuration samples](docs/maven/plugin-configuration-samples.md) to know more.
5151
5252
And execute the next command in project's root folder:
5353

@@ -97,7 +97,7 @@ task packageMyApp(type: io.github.fvarrui.javapackager.gradle.PackageTask, depen
9797
}
9898
```
9999

100-
> See [Gradle plugin configuration samples](docs/gradle-plugin-configuration-samples.md) to know more.
100+
> See [Gradle plugin configuration samples](docs/gradle/plugin-configuration-samples.md) to know more.
101101
102102
And execute the next command in project's root folder:
103103

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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.

docs/maven-plugin-configuration-samples.md renamed to docs/maven/plugin-configuration-samples.md

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Plugin configuration samples
1+
# Plugin configuration samples for Maven
22

33
## Minimal config
44

@@ -150,6 +150,9 @@ Also, JavaPackager plugin is able to get some properties from `pom.xml`, so you
150150
<groupId>io.github.fvarrui</groupId>
151151
<artifactId>javapackager</artifactId>
152152
<version>{latest-plugin-version-here}</version>
153+
<configuration>
154+
<mainClass>fvarrui.sample.Main</mainClass>
155+
</configuration>
153156
<executions>
154157
<execution>
155158
<id>bundle-with-jre</id>
@@ -159,7 +162,6 @@ Also, JavaPackager plugin is able to get some properties from `pom.xml`, so you
159162
</goals>
160163
<configuration>
161164
<name>Sample</name>
162-
<mainClass>fvarrui.sample.Main</mainClass>
163165
<bundleJre>true</bundleJre>
164166
</configuration>
165167
</execution>
@@ -171,7 +173,6 @@ Also, JavaPackager plugin is able to get some properties from `pom.xml`, so you
171173
</goals>
172174
<configuration>
173175
<name>Sample-nojre</name>
174-
<mainClass>fvarrui.sample.Main</mainClass>
175176
<bundleJre>false</bundleJre>
176177
</configuration>
177178
</execution>
@@ -182,3 +183,63 @@ Also, JavaPackager plugin is able to get some properties from `pom.xml`, so you
182183
E.g. on Windows, last configuration will generate next artifacts:
183184
* `Sample_x.y.z.exe` with a bundled JRE.
184185
* `Sample-nojre_x.y.z.exe` without JRE.
186+
187+
## Bundling for multiple platforms
188+
189+
```xml
190+
<plugin>
191+
<groupId>io.github.fvarrui</groupId>
192+
<artifactId>javapackager</artifactId>
193+
<version>{latest-plugin-version-here}</version>
194+
<configuration>
195+
<bundleJre>true</bundleJre>
196+
<mainClass>fvarrui.sample.Main</mainClass>
197+
<generateInstaller>false</generateInstaller>
198+
</configuration>
199+
<executions>
200+
<execution>
201+
<id>bundling-for-windows</id>
202+
<phase>package</phase>
203+
<goals>
204+
<goal>package</goal>
205+
</goals>
206+
<configuration>
207+
<platform>windows</platform>
208+
<createZipball>true</createZipball>
209+
</configuration>
210+
</execution>
211+
<execution>
212+
<id>bundling-for-linux</id>
213+
<phase>package</phase>
214+
<goals>
215+
<goal>package</goal>
216+
</goals>
217+
<configuration>
218+
<platform>linux</platform>
219+
<createTarball>true</createTarball>
220+
<jdkPath>X:\\path\to\linux\jdk</jdkPath>
221+
</configuration>
222+
</execution>
223+
<execution>
224+
<id>bundling-for-mac</id>
225+
<phase>package</phase>
226+
<goals>
227+
<goal>package</goal>
228+
</goals>
229+
<configuration>
230+
<platform>mac</platform>
231+
<createTarball>true</createTarball>
232+
<jdkPath>X:\\path\to\mac\jdk</jdkPath>
233+
</configuration>
234+
</execution>
235+
</executions>
236+
</plugin>
237+
```
238+
239+
E.g. on Windows, last configuration will generate next artifacts:
240+
241+
* `${name}_${version}-linux.tar.gz` with the GNU/Linux application including a customized JRE.
242+
* `${name}_${version}-mac.tar.gz` with the Mac OS X application including a customized JRE.
243+
* `${name}_${version}-windows.zip` with the Windows application including a customized JRE.
244+
245+
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

Comments
 (0)