Skip to content

Commit 4f1b9fc

Browse files
kopporjjohannes
andauthored
Switch to gradlex for modularity (#13112)
* Switch to gradlex * Move javafx plugion to common-conventions * Fix JavaFX patching * Fix controlsfx * Remove version number at Juptier dependency * Switch to jvm-test-suite * Try to fix ControlfsFX * First draft for module test * Remove jvm-test-suite * Try to fix module declarations * WIP: replace org.openjfx.javafxplugin by work of gradlex * Try to fix compilation * jabgui: Compiler error: error: cannot access EventTarget * Add debug output * Remove unused plugin * WIP * Disable graphics "rewrite" * Streamline JavaFX variant handling * Fix exports for jabgui * More dependencies * Add one more dependency * OpenRewrite... * Exclude all kotlin from openrewrite * Remove some "--add-opens" * Fix requirements * Try to remove "module-info.test" * Remove two non-(yet-)needed gradlex plugins * Add missing gradlex module * Add missing requirement --------- Co-authored-by: Jendrik Johannes <jendrik.johannes@gmail.com>
1 parent 6bc772d commit 4f1b9fc

File tree

18 files changed

+249
-246
lines changed

18 files changed

+249
-246
lines changed

build-logic/build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ repositories {
99
}
1010

1111
dependencies {
12+
implementation("org.gradlex:extra-java-module-info:1.12")
13+
implementation("org.gradlex:java-module-packaging:1.0") // required for platform-specific packaging of JavaFX dependencies
14+
implementation("org.gradlex:java-module-testing:1.7")
15+
implementation("org.gradlex.jvm-dependency-conflict-resolution:org.gradlex.jvm-dependency-conflict-resolution.gradle.plugin:2.3")
16+
1217
configurations
1318
.matching { it.name.contains("downloadSources") }
1419
.configureEach {

build-logic/src/main/kotlin/buildlogic.java-common-conventions.gradle.kts

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.gradle.internal.os.OperatingSystem
2+
13
plugins {
24
java
35

@@ -6,6 +8,11 @@ plugins {
68
// id("jacoco")
79

810
id("project-report")
11+
12+
id("org.gradlex.extra-java-module-info")
13+
id("org.gradlex.java-module-testing")
14+
id("org.gradlex.jvm-dependency-conflict-resolution")
15+
id("org.gradlex.java-module-packaging")
916
}
1017

1118
repositories {
@@ -26,10 +33,136 @@ dependencies {
2633
}
2734
}
2835

36+
val os = OperatingSystem.current()
37+
38+
val osTarget = when {
39+
os.isMacOsX -> {
40+
val osVersion = System.getProperty("os.version")
41+
if (osVersion.startsWith("14")) "macos-14" else "macos-13"
42+
}
43+
os.isLinux -> "ubuntu-22.04"
44+
os.isWindows -> "windows-2022"
45+
else -> error("Unsupported OS")
46+
}
47+
48+
// Source: https://github.com/jjohannes/java-module-system/blob/main/gradle/plugins/src/main/kotlin/targets.gradle.kts
49+
// Configure variants for OS
50+
javaModulePackaging {
51+
target("ubuntu-22.04") {
52+
operatingSystem = OperatingSystemFamily.LINUX
53+
architecture = MachineArchitecture.X86_64
54+
packageTypes = listOf("deb")
55+
}
56+
target("macos-13") {
57+
operatingSystem = OperatingSystemFamily.MACOS
58+
architecture = MachineArchitecture.X86_64
59+
packageTypes = listOf("dmg")
60+
}
61+
target("macos-14") {
62+
operatingSystem = OperatingSystemFamily.MACOS
63+
architecture = MachineArchitecture.ARM64
64+
packageTypes = listOf("dmg")
65+
}
66+
target("windows-2022") {
67+
operatingSystem = OperatingSystemFamily.WINDOWS
68+
architecture = MachineArchitecture.X86_64
69+
packageTypes = listOf("exe")
70+
}
71+
primaryTarget(target(osTarget))
72+
}
73+
74+
// Tell gradle which jar to use for which platform
75+
// Source: https://github.com/jjohannes/java-module-system/blob/be19f6c088dca511b6d9a7487dacf0b715dbadc1/gradle/plugins/src/main/kotlin/metadata-patch.gradle.kts#L14-L22
76+
jvmDependencyConflicts.patch {
77+
listOf("base", "controls", "fxml", "graphics", "swing", "web", "media").forEach { jfxModule ->
78+
module("org.openjfx:javafx-$jfxModule") {
79+
addTargetPlatformVariant("", "none", "none") // matches the empty Jars: to get better errors
80+
addTargetPlatformVariant("linux", OperatingSystemFamily.LINUX, MachineArchitecture.X86_64)
81+
addTargetPlatformVariant("linux-aarch64", OperatingSystemFamily.LINUX, MachineArchitecture.ARM64)
82+
addTargetPlatformVariant("mac", OperatingSystemFamily.MACOS, MachineArchitecture.X86_64)
83+
addTargetPlatformVariant("mac-aarch64", OperatingSystemFamily.MACOS, MachineArchitecture.ARM64)
84+
addTargetPlatformVariant("win", OperatingSystemFamily.WINDOWS, MachineArchitecture.X86_64)
85+
}
86+
}
87+
// Source: https://github.com/jjohannes/java-module-system/blob/be19f6c088dca511b6d9a7487dacf0b715dbadc1/gradle/plugins/src/main/kotlin/metadata-patch.gradle.kts#L9
88+
module("com.google.guava:guava") {
89+
removeDependency("com.google.code.findbugs:jsr305")
90+
removeDependency("org.checkerframework:checker-qual")
91+
removeDependency("com.google.errorprone:error_prone_annotations")
92+
}
93+
}
94+
95+
extraJavaModuleInfo {
96+
failOnMissingModuleInfo = false
97+
failOnAutomaticModules = false
98+
// skipLocalJars = true
99+
deriveAutomaticModuleNamesFromFileNames = true
100+
101+
module("org.openjfx:javafx-base", "javafx.base") {
102+
overrideModuleName()
103+
patchRealModule()
104+
// jabgui requires at least "javafx.collections"
105+
exportAllPackages()
106+
}
107+
108+
// required for testing of jablib
109+
module("org.openjfx:javafx-fxml", "javafx.fxml") {
110+
patchRealModule()
111+
exportAllPackages()
112+
113+
requiresTransitive("javafx.base")
114+
requiresTransitive("javafx.graphics")
115+
requiresTransitive("java.desktop")
116+
}
117+
118+
// required for testing
119+
module("org.openjfx:javafx-graphics", "javafx.graphics") {
120+
patchRealModule()
121+
exportAllPackages()
122+
123+
requiresTransitive("javafx.base")
124+
requiresTransitive("java.desktop")
125+
requiresTransitive("jdk.unsupported")
126+
}
127+
128+
module("org.controlsfx:controlsfx", "org.controlsfx.controls") {
129+
patchRealModule()
130+
131+
exports("impl.org.controlsfx.skin")
132+
exports("org.controlsfx.control")
133+
exports("org.controlsfx.control.action")
134+
exports("org.controlsfx.control.decoration")
135+
exports("org.controlsfx.control.table")
136+
exports("org.controlsfx.control.textfield")
137+
exports("org.controlsfx.dialog")
138+
exports("org.controlsfx.validation")
139+
exports("org.controlsfx.validation.decoration")
140+
141+
requires("javafx.base")
142+
requires("javafx.controls")
143+
requires("javafx.graphics")
144+
}
145+
146+
module("org.openjfx:javafx-controls", "javafx.controls") {
147+
patchRealModule()
148+
149+
requiresTransitive("javafx.base");
150+
requiresTransitive("javafx.graphics");
151+
152+
exports("javafx.scene.chart")
153+
exports("javafx.scene.control")
154+
exports("javafx.scene.control.cell")
155+
exports("javafx.scene.control.skin")
156+
157+
// PATCH REASON:
158+
exports("com.sun.javafx.scene.control")
159+
}
160+
}
161+
29162
testing {
30163
suites {
31164
val test by getting(JvmTestSuite::class) {
32-
useJUnitJupiter("5.12.2")
165+
useJUnitJupiter()
33166
}
34167
}
35168
}

build.gradle.kts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ plugins {
99
id("org.itsallcode.openfasttrace") version "3.0.1"
1010

1111
id("com.adarshr.test-logger") version "4.0.0"
12-
13-
// This is https://github.com/java9-modularity/gradle-modules-plugin/pull/282
14-
id("com.github.koppor.gradle-modules-plugin") version "v1.8.15-cmd-1"
1512
}
1613

1714
// OpenRewrite should rewrite all sources
@@ -29,11 +26,11 @@ rewrite {
2926
activeRecipe("org.jabref.config.rewrite.cleanup")
3027
exclusion(
3128
"settings.gradle",
32-
"**/build.gradle.kts",
3329
"**/generated-sources/**",
3430
"**/src/main/resources/**",
3531
"**/src/test/resources/**",
3632
"**/module-info.java",
33+
"**/*.kts",
3734
"**/*.py",
3835
"**/*.xml",
3936
"**/*.yml"
@@ -62,8 +59,6 @@ subprojects {
6259
// Hint from https://stackoverflow.com/a/46533151/873282
6360
plugins.apply("com.adarshr.test-logger")
6461

65-
plugins.apply("com.github.koppor.gradle-modules-plugin")
66-
6762
checkstyle {
6863
toolVersion = "10.23.0"
6964
configFile = rootProject.file("config/checkstyle/checkstyle.xml")

gradle.properties

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ org.gradle.vfs.watch=true
55
org.gradle.jvmargs=-Xmx6096M
66

77
# hint by https://docs.gradle.org/current/userguide/performance.html#enable_configuration_cache
8-
# Does not work:
9-
# - Task `:compileJava` of type `org.gradle.api.tasks.compile.JavaCompile`: cannot serialize object of type 'org.gradle.api.internal.project.DefaultProject', a subtype of 'org.gradle.api.Project', as these are not supported with the configuration cache.
10-
# org.gradle.configuration-cache=false
8+
# Currently does not work as "Invocation of 'Task.project' by task ':jablib:schemaGen_org-jabref-logic-importer-fileformat-citavi' at execution time is unsupported."
9+
# org.gradle.configuration-cache=true
1110

1211
# hint by https://docs.gradle.org/current/userguide/performance.html#enable_the_build_cache
1312
org.gradle.caching=true

jabgui/build.gradle.kts

Lines changed: 30 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11

22
import org.gradle.internal.os.OperatingSystem
3-
import org.javamodularity.moduleplugin.extensions.CompileModuleOptions
4-
import org.javamodularity.moduleplugin.extensions.RunModuleOptions
53

64
plugins {
75
id("buildlogic.java-common-conventions")
86

97
application
108

11-
id("org.openjfx.javafxplugin") version("0.1.0")
12-
139
// Do not activate; causes issues with the modularity plugin (no tests found etc)
1410
// id("com.redock.classpathtofile") version "0.1.0"
1511

@@ -22,9 +18,19 @@ version = project.findProperty("projVersion") ?: "100.0.0"
2218
val luceneVersion = "10.2.1"
2319
val pdfbox = "3.0.5"
2420

21+
val javafxVersion = "24.0.1"
22+
2523
dependencies {
2624
implementation(project(":jablib"))
2725

26+
implementation("org.openjfx:javafx-base:$javafxVersion")
27+
implementation("org.openjfx:javafx-controls:$javafxVersion")
28+
implementation("org.openjfx:javafx-fxml:$javafxVersion")
29+
// implementation("org.openjfx:javafx-graphics:24.0.1")
30+
implementation("org.openjfx:javafx-graphics:$javafxVersion")
31+
implementation("org.openjfx:javafx-swing:$javafxVersion")
32+
implementation("org.openjfx:javafx-web:$javafxVersion")
33+
2834
implementation("org.slf4j:slf4j-api:2.0.17")
2935
implementation("org.tinylog:tinylog-api:2.7.0")
3036
implementation("org.tinylog:slf4j-tinylog:2.7.0")
@@ -138,12 +144,6 @@ dependencies {
138144
testImplementation("com.github.javaparser:javaparser-symbol-solver-core:3.26.4")
139145
}
140146

141-
javafx {
142-
version = "24"
143-
// javafx.swing required by com.dlsc.gemsfx
144-
modules = listOf("javafx.base", "javafx.graphics", "javafx.fxml", "javafx.web", "javafx.swing")
145-
}
146-
147147
application {
148148
mainClass.set("org.jabref.Launcher")
149149
mainModule.set("org.jabref")
@@ -187,10 +187,6 @@ application {
187187
)
188188
}
189189

190-
// Workaround for https://github.com/openjfx/javafx-gradle-plugin/issues/89
191-
// See also https://github.com/java9-modularity/gradle-modules-plugin/issues/165
192-
modularity.disableEffectiveArgumentsAdjustment()
193-
194190
/*
195191
jacoco {
196192
toolVersion = "0.8.13"
@@ -204,65 +200,10 @@ tasks.named<JavaExec>("run") {
204200
doFirst {
205201
// Clear the default JVM arguments to avoid warnings
206202
// application.applicationDefaultJvmArgs = emptyList()
207-
application.applicationDefaultJvmArgs = listOf("--enable-native-access=ai.djl.tokenizers,ai.djl.pytorch_engine,com.sun.jna,javafx.graphics,javafx.media,javafx.web,org.apache.lucene.core")
208-
}
209-
210-
extensions.configure<RunModuleOptions>("moduleOptions") {
211-
// On a change here, also adapt "application > applicationDefaultJvmArgs"
212-
addExports.putAll(
213-
mapOf(
214-
// TODO: Remove access to internal API
215-
"javafx.base/com.sun.javafx.event" to "org.jabref.merged.module",
216-
"javafx.controls/com.sun.javafx.scene.control" to "org.jabref",
217-
218-
// ControlsFX compatibility
219-
// We need to restate the ControlsFX exports, because we get following error otherwise:
220-
// java.lang.IllegalAccessError:
221-
// class org.controlsfx.control.textfield.AutoCompletionBinding (in module org.controlsfx.controls)
222-
// cannot access class com.sun.javafx.event.EventHandlerManager (in module javafx.base) because
223-
// module javafx.base does not export com.sun.javafx.event to module org.controlsfx.controls
224-
// Taken from here: https://github.com/controlsfx/controlsfx/blob/9.0.0/build.gradle#L1
225-
"javafx.graphics/com.sun.javafx.scene" to "org.controlsfx.controls",
226-
"javafx.graphics/com.sun.javafx.scene.traversal" to "org.controlsfx.controls",
227-
"javafx.graphics/com.sun.javafx.css" to "org.controlsfx.controls",
228-
"javafx.controls/com.sun.javafx.scene.control" to "org.controlsfx.controls",
229-
"javafx.controls/com.sun.javafx.scene.control.behavior" to "org.controlsfx.controls",
230-
"javafx.controls/com.sun.javafx.scene.control.inputmap" to "org.controlsfx.controls",
231-
"javafx.base/com.sun.javafx.event" to "org.controlsfx.controls",
232-
"javafx.base/com.sun.javafx.collections" to "org.controlsfx.controls",
233-
"javafx.base/com.sun.javafx.runtime" to "org.controlsfx.controls",
234-
"javafx.web/com.sun.webkit" to "org.controlsfx.controls"
235-
)
236-
)
237-
238-
addOpens.putAll(
239-
mapOf(
240-
"javafx.controls/javafx.scene.control" to "org.jabref",
241-
"javafx.controls/com.sun.javafx.scene.control" to "org.jabref",
242-
"org.controlsfx.controls/impl.org.controlsfx.skin" to "org.jabref",
243-
"org.controlsfx.controls/org.controlsfx.control.textfield" to "org.jabref",
244-
"javafx.controls/javafx.scene.control.skin" to "org.controlsfx.controls",
245-
"javafx.graphics/javafx.scene" to "org.controlsfx.controls",
246-
"javafx.base/javafx.collections" to "org.jabref",
247-
"javafx.base/javafx.collections.transformation" to "org.jabref"
248-
)
249-
)
250-
251-
addModules.add("jdk.incubator.vector")
252-
253-
createCommandLineArgumentFile = true
254-
}
255-
}
256-
257-
tasks.compileJava {
258-
extensions.configure<CompileModuleOptions> {
259-
addExports.putAll(
260-
mapOf(
261-
// TODO: Remove access to internal api
262-
"javafx.controls/com.sun.javafx.scene.control" to "org.jabref",
263-
"org.controlsfx.controls/impl.org.controlsfx.skin" to "org.jabref"
203+
application.applicationDefaultJvmArgs =
204+
listOf(
205+
"--enable-native-access=ai.djl.tokenizers,ai.djl.pytorch_engine,com.sun.jna,javafx.graphics,javafx.media,javafx.web,org.apache.lucene.core"
264206
)
265-
)
266207
}
267208
}
268209

@@ -290,7 +231,8 @@ jlink {
290231
"zip-6",
291232
"--no-header-files",
292233
"--no-man-pages",
293-
"--bind-services"
234+
"--bind-services",
235+
"--add-modules", "jdk.incubator.vector"
294236
)
295237

296238
launcher {
@@ -493,3 +435,18 @@ if (OperatingSystem.current().isWindows) {
493435
}
494436
}
495437
}
438+
439+
javaModuleTesting.whitebox(testing.suites["test"]) {
440+
requires.add("org.junit.jupiter.api")
441+
requires.add("org.junit.jupiter.params")
442+
requires.add("org.mockito")
443+
requires.add("org.jabref.testsupport")
444+
}
445+
446+
tasks.test {
447+
jvmArgs = listOf(
448+
"--add-opens", "javafx.graphics/com.sun.javafx.application=org.testfx",
449+
"--add-reads", "org.mockito=java.prefs",
450+
"--add-reads", "org.mockito=javafx.scene",
451+
)
452+
}

jabgui/src/main/java/module-info.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010

1111
// region JavaFX
1212
requires javafx.base;
13-
requires javafx.graphics;
1413
requires javafx.controls;
15-
requires javafx.web;
1614
requires javafx.fxml;
15+
requires javafx.graphics;
16+
requires javafx.web;
17+
1718
requires com.tobiasdiez.easybind;
1819

1920
requires afterburner.fx;

0 commit comments

Comments
 (0)