Skip to content

Commit 24ea6fe

Browse files
committed
Extend documentation
1 parent 34746ba commit 24ea6fe

File tree

1 file changed

+78
-7
lines changed

1 file changed

+78
-7
lines changed

README.md

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
A Gradle plugin to package modular Java application as standalone bundles/installers for Windows, macOS and Linux with [jpackage](https://docs.oracle.com/en/java/javase/21/docs/specs/man/jpackage.html).
77

8-
This plugin is maintained by me, [Jendrik Johannes](https://github.com/jjohannes).
8+
This [GradleX](https://gradlex.org) plugin is maintained by me, [Jendrik Johannes](https://github.com/jjohannes).
99
I offer consulting and training for Gradle and/or the Java Module System - please [reach out](mailto:[email protected]) if you are interested.
1010
There is also my [YouTube channel](https://www.youtube.com/playlist?list=PLWQK2ZdV4Yl2k2OmC_gsjDpdIBTN0qqkE) on Gradle topics.
1111

@@ -17,16 +17,15 @@ If you plan to build Java Modules with Gradle, you should consider using these p
1717

1818
- [`id("org.gradlex.java-module-dependencies")`](https://github.com/gradlex-org/java-module-dependencies)
1919
Avoid duplicated dependency definitions and get your Module Path under control
20+
- [`id("org.gradlex.jvm-dependency-conflict-resolution")`](https://github.com/gradlex-org/jvm-dependency-conflict-resolution)
21+
Additional metadata for widely-used modules and patching facilities to add missing metadata
2022
- [`id("org.gradlex.java-module-testing")`](https://github.com/gradlex-org/java-module-testing)
2123
Proper test setup for Java Modules
2224
- [`id("org.gradlex.extra-java-module-info")`](https://github.com/gradlex-org/extra-java-module-info)
2325
Only if your (existing) project cannot avoid using non-module legacy Jars
2426
- [`id("org.gradlex.java-module-packaging")`](https://github.com/gradlex-org/java-module-packaging)
2527
Package standalone applications for Windows, macOS and Linux
2628

27-
[Here is a sample](https://github.com/gradlex-org/java-module-testing/tree/main/samples/use-all-java-module-plugins)
28-
that shows all plugins in combination.
29-
3029
[In episodes 31, 32, 33 of Understanding Gradle](https://github.com/jjohannes/understanding-gradle) I explain what these plugins do and why they are needed.
3130
[<img src="https://onepiecesoftware.github.io/img/videos/31.png" width="260">](https://www.youtube.com/watch?v=X9u1taDwLSA&list=PLWQK2ZdV4Yl2k2OmC_gsjDpdIBTN0qqkE)
3231
[<img src="https://onepiecesoftware.github.io/img/videos/32.png" width="260">](https://www.youtube.com/watch?v=T9U0BOlVc-c&list=PLWQK2ZdV4Yl2k2OmC_gsjDpdIBTN0qqkE)
@@ -37,6 +36,10 @@ that shows all plugins in combination.
3736

3837
# How to use?
3938

39+
Working example projects to inspect:
40+
- [java-module-system](https://github.com/jjohannes/java-module-system) contains a compact sample and further documentation
41+
- [gradle-project-setup-howto](https://github.com/jjohannes/gradle-project-setup-howto/tree/java_module_system) is a full-fledged Java Module System project setup
42+
4043
For general information about how to structure Gradle builds and apply community plugins like this one to all subprojects
4144
you can check out my [Understanding Gradle video series](https://www.youtube.com/playlist?list=PLWQK2ZdV4Yl2k2OmC_gsjDpdIBTN0qqkE).
4245

@@ -80,18 +83,86 @@ javaModulePackaging {
8083
}
8184
```
8285

83-
## How ot use?
84-
85-
You can now run _target_ specific builds:
86+
You can now run _target-specific_ builds:
8687

8788
```
8889
./gradlew assembleWindows
8990
```
9091

92+
```
93+
./gradlew runWindows
94+
```
95+
9196
## Using target specific variants of libraries (like JavaFX)
9297

98+
The plugin uses Gradle's [variant-aware dependency management](https://docs.gradle.org/current/userguide/variant_model.html)
99+
to select target-specific Jars based on the configured [targets](#apply-and-use-the-plugin).
100+
For this, such a library needs to be published with [Gradle Module Metadata](https://docs.gradle.org/current/userguide/publishing_gradle_module_metadata.html)
101+
and contain the necessary information about the available target-specific Jars.
102+
If the metadata is missing or incomplete, you should use the [org.gradlex.jvm-dependency-conflict-resolution](https://github.com/gradlex-org/jvm-dependency-conflict-resolution)
103+
plugin to add the missing information via [addTargetPlatformVariant](https://gradlex.org/jvm-dependency-conflict-resolution/#patch-dsl-block).
104+
105+
For example, for JavaFX it may look like this:
106+
```
107+
jvmDependencyConflicts.patch {
108+
listOf("base", "graphics", "controls").forEach { jfxModule ->
109+
module("org.openjfx:javafx-$jfxModule") {
110+
addTargetPlatformVariant("linux", OperatingSystemFamily.LINUX, MachineArchitecture.X86_64)
111+
addTargetPlatformVariant("linux-aarch64", OperatingSystemFamily.LINUX, MachineArchitecture.ARM64)
112+
addTargetPlatformVariant("mac", OperatingSystemFamily.MACOS, MachineArchitecture.X86_64)
113+
addTargetPlatformVariant("mac-aarch64", OperatingSystemFamily.MACOS, MachineArchitecture.ARM64)
114+
addTargetPlatformVariant("win", OperatingSystemFamily.WINDOWS, MachineArchitecture.X86_64)
115+
}
116+
}
117+
}
118+
```
119+
93120
## Running on GitHub Actions
94121

122+
Target-specific _tasks_ such as `assembleWindows-2022` or `assembleMacos-14` only run on the fitting operating system and architecture.
123+
If you want to build your software for multiple targets and have GitHub actions available, you can use different
124+
runners to create packages for the different targets. A setup for this can look like this
125+
(assuming your targets are named: `ubuntu-22.04`, `windows-2022`, `macos-13`, `macos-14`):
126+
127+
```
128+
jobs:
129+
check:
130+
runs-on: ubuntu-latest
131+
steps:
132+
- uses: actions/checkout@v4
133+
- uses: actions/setup-java@v4
134+
with:
135+
distribution: temurin
136+
java-version-file: ./gradle/java-version.txt
137+
- uses: gradle/actions/setup-gradle@v3
138+
- run: "./gradlew check"
139+
140+
package:
141+
needs: check
142+
strategy:
143+
matrix:
144+
os: [ubuntu-22.04, windows-2022, macos-13, macos-14]
145+
runs-on: ${{ matrix.os }}
146+
steps:
147+
- uses: actions/checkout@v4
148+
- uses: actions/setup-java@v4
149+
with:
150+
distribution: temurin
151+
java-version-file: ./gradle/java-version.txt
152+
- uses: gradle/actions/setup-gradle@v3
153+
- run: "./gradlew assemble${{ matrix.os }}"
154+
- uses: actions/upload-artifact@v4
155+
with:
156+
name: Application Package ${{ matrix.os }}
157+
path: build/app/packages/*/*
158+
```
159+
160+
To avoid re-compilation of the Java code on each of the runners, you can run a
161+
[Gradle remote cache node](https://docs.gradle.com/build-cache-node).
162+
163+
The [java-module-system](https://github.com/jjohannes/java-module-system) project is an example that
164+
uses GitHub actions with a Gradle remote build cache.
165+
95166
# Disclaimer
96167

97168
Gradle and the Gradle logo are trademarks of Gradle, Inc.

0 commit comments

Comments
 (0)