Skip to content

Switch to gradlex for modularity #13112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Jun 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2f600e7
Switch to gradlex
koppor May 13, 2025
a78fffa
Move javafx plugion to common-conventions
koppor May 13, 2025
383eff7
Fix JavaFX patching
koppor May 13, 2025
34c53ec
Fix controlsfx
koppor May 13, 2025
c367d10
Remove version number at Juptier dependency
koppor May 13, 2025
369cfd3
Switch to jvm-test-suite
koppor May 13, 2025
fcd2c64
Try to fix ControlfsFX
koppor May 13, 2025
36d6904
First draft for module test
koppor May 13, 2025
08489ee
Remove jvm-test-suite
koppor May 14, 2025
5c4e882
Try to fix module declarations
koppor May 14, 2025
3c8073c
WIP: replace org.openjfx.javafxplugin by work of gradlex
koppor May 15, 2025
9d39689
Try to fix compilation
koppor May 15, 2025
4d654de
jabgui: Compiler error: error: cannot access EventTarget
koppor May 15, 2025
27e7063
Add debug output
koppor May 15, 2025
b941af0
Merge branch 'main' into ok-branch-3
koppor May 15, 2025
5163061
Remove unused plugin
koppor May 16, 2025
8c2d981
WIP
koppor May 21, 2025
bd209b5
Disable graphics "rewrite"
koppor May 21, 2025
c5d1259
Merge remote-tracking branch 'origin/main' into ok-branch-3
koppor May 22, 2025
daee105
Merge remote-tracking branch 'origin/main' into ok-branch-3
koppor May 31, 2025
a183747
Merge branch 'main' into ok-branch-3
koppor May 31, 2025
3f3e38e
Streamline JavaFX variant handling
jjohannes May 29, 2025
b8d7de4
Fix exports for jabgui
koppor May 31, 2025
fd6aa07
More dependencies
koppor May 31, 2025
db22347
Add one more dependency
koppor May 31, 2025
6dbf25d
OpenRewrite...
koppor May 31, 2025
0686ec5
Exclude all kotlin from openrewrite
koppor May 31, 2025
910f6c2
Remove some "--add-opens"
koppor May 31, 2025
8780265
Fix requirements
koppor May 31, 2025
10a56cd
Try to remove "module-info.test"
koppor May 31, 2025
9e5d72a
Remove two non-(yet-)needed gradlex plugins
koppor May 31, 2025
cd0679c
Merge branch 'ok-branch-3' of github.com:JabRef/jabref into ok-branch-3
koppor May 31, 2025
96490cd
Add missing gradlex module
koppor May 31, 2025
67f4fe8
Add missing requirement
koppor Jun 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ repositories {
}

dependencies {
implementation("org.gradlex:extra-java-module-info:1.12")
implementation("org.gradlex:java-module-packaging:1.0") // required for platform-specific packaging of JavaFX dependencies
implementation("org.gradlex:java-module-testing:1.7")
implementation("org.gradlex.jvm-dependency-conflict-resolution:org.gradlex.jvm-dependency-conflict-resolution.gradle.plugin:2.3")

configurations
.matching { it.name.contains("downloadSources") }
.configureEach {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.gradle.internal.os.OperatingSystem

plugins {
java

Expand All @@ -6,6 +8,11 @@ plugins {
// id("jacoco")

id("project-report")

id("org.gradlex.extra-java-module-info")
id("org.gradlex.java-module-testing")
id("org.gradlex.jvm-dependency-conflict-resolution")
id("org.gradlex.java-module-packaging")
}

repositories {
Expand All @@ -26,10 +33,136 @@ dependencies {
}
}

val os = OperatingSystem.current()

val osTarget = when {
os.isMacOsX -> {
val osVersion = System.getProperty("os.version")
if (osVersion.startsWith("14")) "macos-14" else "macos-13"
}
os.isLinux -> "ubuntu-22.04"
os.isWindows -> "windows-2022"
else -> error("Unsupported OS")
}

// Source: https://github.com/jjohannes/java-module-system/blob/main/gradle/plugins/src/main/kotlin/targets.gradle.kts
// Configure variants for OS
javaModulePackaging {
target("ubuntu-22.04") {
operatingSystem = OperatingSystemFamily.LINUX
architecture = MachineArchitecture.X86_64
packageTypes = listOf("deb")
}
target("macos-13") {
operatingSystem = OperatingSystemFamily.MACOS
architecture = MachineArchitecture.X86_64
packageTypes = listOf("dmg")
}
target("macos-14") {
operatingSystem = OperatingSystemFamily.MACOS
architecture = MachineArchitecture.ARM64
packageTypes = listOf("dmg")
}
target("windows-2022") {
operatingSystem = OperatingSystemFamily.WINDOWS
architecture = MachineArchitecture.X86_64
packageTypes = listOf("exe")
}
primaryTarget(target(osTarget))
}

// Tell gradle which jar to use for which platform
// Source: https://github.com/jjohannes/java-module-system/blob/be19f6c088dca511b6d9a7487dacf0b715dbadc1/gradle/plugins/src/main/kotlin/metadata-patch.gradle.kts#L14-L22
jvmDependencyConflicts.patch {
listOf("base", "controls", "fxml", "graphics", "swing", "web", "media").forEach { jfxModule ->
module("org.openjfx:javafx-$jfxModule") {
addTargetPlatformVariant("", "none", "none") // matches the empty Jars: to get better errors
addTargetPlatformVariant("linux", OperatingSystemFamily.LINUX, MachineArchitecture.X86_64)
addTargetPlatformVariant("linux-aarch64", OperatingSystemFamily.LINUX, MachineArchitecture.ARM64)
addTargetPlatformVariant("mac", OperatingSystemFamily.MACOS, MachineArchitecture.X86_64)
addTargetPlatformVariant("mac-aarch64", OperatingSystemFamily.MACOS, MachineArchitecture.ARM64)
addTargetPlatformVariant("win", OperatingSystemFamily.WINDOWS, MachineArchitecture.X86_64)
}
}
// Source: https://github.com/jjohannes/java-module-system/blob/be19f6c088dca511b6d9a7487dacf0b715dbadc1/gradle/plugins/src/main/kotlin/metadata-patch.gradle.kts#L9
module("com.google.guava:guava") {
removeDependency("com.google.code.findbugs:jsr305")
removeDependency("org.checkerframework:checker-qual")
removeDependency("com.google.errorprone:error_prone_annotations")
}
}

extraJavaModuleInfo {
failOnMissingModuleInfo = false
failOnAutomaticModules = false
// skipLocalJars = true
deriveAutomaticModuleNamesFromFileNames = true

module("org.openjfx:javafx-base", "javafx.base") {
overrideModuleName()
patchRealModule()
// jabgui requires at least "javafx.collections"
exportAllPackages()
}

// required for testing of jablib
module("org.openjfx:javafx-fxml", "javafx.fxml") {
patchRealModule()
exportAllPackages()

requiresTransitive("javafx.base")
requiresTransitive("javafx.graphics")
requiresTransitive("java.desktop")
}

// required for testing
module("org.openjfx:javafx-graphics", "javafx.graphics") {
patchRealModule()
exportAllPackages()

requiresTransitive("javafx.base")
requiresTransitive("java.desktop")
requiresTransitive("jdk.unsupported")
}

module("org.controlsfx:controlsfx", "org.controlsfx.controls") {
patchRealModule()

exports("impl.org.controlsfx.skin")
exports("org.controlsfx.control")
exports("org.controlsfx.control.action")
exports("org.controlsfx.control.decoration")
exports("org.controlsfx.control.table")
exports("org.controlsfx.control.textfield")
exports("org.controlsfx.dialog")
exports("org.controlsfx.validation")
exports("org.controlsfx.validation.decoration")

requires("javafx.base")
requires("javafx.controls")
requires("javafx.graphics")
}

module("org.openjfx:javafx-controls", "javafx.controls") {
patchRealModule()

requiresTransitive("javafx.base");
requiresTransitive("javafx.graphics");

exports("javafx.scene.chart")
exports("javafx.scene.control")
exports("javafx.scene.control.cell")
exports("javafx.scene.control.skin")

// PATCH REASON:
exports("com.sun.javafx.scene.control")
}
}

testing {
suites {
val test by getting(JvmTestSuite::class) {
useJUnitJupiter("5.12.2")
useJUnitJupiter()
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ plugins {
id("org.itsallcode.openfasttrace") version "3.0.1"

id("com.adarshr.test-logger") version "4.0.0"

// This is https://github.com/java9-modularity/gradle-modules-plugin/pull/282
id("com.github.koppor.gradle-modules-plugin") version "v1.8.15-cmd-1"
}

// OpenRewrite should rewrite all sources
Expand All @@ -29,11 +26,11 @@ rewrite {
activeRecipe("org.jabref.config.rewrite.cleanup")
exclusion(
"settings.gradle",
"**/build.gradle.kts",
"**/generated-sources/**",
"**/src/main/resources/**",
"**/src/test/resources/**",
"**/module-info.java",
"**/*.kts",
"**/*.py",
"**/*.xml",
"**/*.yml"
Expand Down Expand Up @@ -62,8 +59,6 @@ subprojects {
// Hint from https://stackoverflow.com/a/46533151/873282
plugins.apply("com.adarshr.test-logger")

plugins.apply("com.github.koppor.gradle-modules-plugin")

checkstyle {
toolVersion = "10.23.0"
configFile = rootProject.file("config/checkstyle/checkstyle.xml")
Expand Down
5 changes: 2 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ org.gradle.vfs.watch=true
org.gradle.jvmargs=-Xmx6096M

# hint by https://docs.gradle.org/current/userguide/performance.html#enable_configuration_cache
# Does not work:
# - 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.
# org.gradle.configuration-cache=false
# Currently does not work as "Invocation of 'Task.project' by task ':jablib:schemaGen_org-jabref-logic-importer-fileformat-citavi' at execution time is unsupported."
# org.gradle.configuration-cache=true

# hint by https://docs.gradle.org/current/userguide/performance.html#enable_the_build_cache
org.gradle.caching=true
Expand Down
103 changes: 30 additions & 73 deletions jabgui/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@

import org.gradle.internal.os.OperatingSystem
import org.javamodularity.moduleplugin.extensions.CompileModuleOptions
import org.javamodularity.moduleplugin.extensions.RunModuleOptions

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

application

id("org.openjfx.javafxplugin") version("0.1.0")

// Do not activate; causes issues with the modularity plugin (no tests found etc)
// id("com.redock.classpathtofile") version "0.1.0"

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

val javafxVersion = "24.0.1"

dependencies {
implementation(project(":jablib"))

implementation("org.openjfx:javafx-base:$javafxVersion")
implementation("org.openjfx:javafx-controls:$javafxVersion")
implementation("org.openjfx:javafx-fxml:$javafxVersion")
// implementation("org.openjfx:javafx-graphics:24.0.1")
implementation("org.openjfx:javafx-graphics:$javafxVersion")
implementation("org.openjfx:javafx-swing:$javafxVersion")
implementation("org.openjfx:javafx-web:$javafxVersion")

implementation("org.slf4j:slf4j-api:2.0.17")
implementation("org.tinylog:tinylog-api:2.7.0")
implementation("org.tinylog:slf4j-tinylog:2.7.0")
Expand Down Expand Up @@ -134,12 +140,6 @@ dependencies {
testImplementation("com.github.javaparser:javaparser-symbol-solver-core:3.26.4")
}

javafx {
version = "24"
// javafx.swing required by com.dlsc.gemsfx
modules = listOf("javafx.base", "javafx.graphics", "javafx.fxml", "javafx.web", "javafx.swing")
}

application {
mainClass.set("org.jabref.Launcher")
mainModule.set("org.jabref")
Expand Down Expand Up @@ -183,10 +183,6 @@ application {
)
}

// Workaround for https://github.com/openjfx/javafx-gradle-plugin/issues/89
// See also https://github.com/java9-modularity/gradle-modules-plugin/issues/165
modularity.disableEffectiveArgumentsAdjustment()

/*
jacoco {
toolVersion = "0.8.13"
Expand All @@ -200,65 +196,10 @@ tasks.named<JavaExec>("run") {
doFirst {
// Clear the default JVM arguments to avoid warnings
// application.applicationDefaultJvmArgs = emptyList()
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")
}

extensions.configure<RunModuleOptions>("moduleOptions") {
// On a change here, also adapt "application > applicationDefaultJvmArgs"
addExports.putAll(
mapOf(
// TODO: Remove access to internal API
"javafx.base/com.sun.javafx.event" to "org.jabref.merged.module",
"javafx.controls/com.sun.javafx.scene.control" to "org.jabref",

// ControlsFX compatibility
// We need to restate the ControlsFX exports, because we get following error otherwise:
// java.lang.IllegalAccessError:
// class org.controlsfx.control.textfield.AutoCompletionBinding (in module org.controlsfx.controls)
// cannot access class com.sun.javafx.event.EventHandlerManager (in module javafx.base) because
// module javafx.base does not export com.sun.javafx.event to module org.controlsfx.controls
// Taken from here: https://github.com/controlsfx/controlsfx/blob/9.0.0/build.gradle#L1
"javafx.graphics/com.sun.javafx.scene" to "org.controlsfx.controls",
"javafx.graphics/com.sun.javafx.scene.traversal" to "org.controlsfx.controls",
"javafx.graphics/com.sun.javafx.css" to "org.controlsfx.controls",
"javafx.controls/com.sun.javafx.scene.control" to "org.controlsfx.controls",
"javafx.controls/com.sun.javafx.scene.control.behavior" to "org.controlsfx.controls",
"javafx.controls/com.sun.javafx.scene.control.inputmap" to "org.controlsfx.controls",
"javafx.base/com.sun.javafx.event" to "org.controlsfx.controls",
"javafx.base/com.sun.javafx.collections" to "org.controlsfx.controls",
"javafx.base/com.sun.javafx.runtime" to "org.controlsfx.controls",
"javafx.web/com.sun.webkit" to "org.controlsfx.controls"
)
)

addOpens.putAll(
mapOf(
"javafx.controls/javafx.scene.control" to "org.jabref",
"javafx.controls/com.sun.javafx.scene.control" to "org.jabref",
"org.controlsfx.controls/impl.org.controlsfx.skin" to "org.jabref",
"org.controlsfx.controls/org.controlsfx.control.textfield" to "org.jabref",
"javafx.controls/javafx.scene.control.skin" to "org.controlsfx.controls",
"javafx.graphics/javafx.scene" to "org.controlsfx.controls",
"javafx.base/javafx.collections" to "org.jabref",
"javafx.base/javafx.collections.transformation" to "org.jabref"
)
)

addModules.add("jdk.incubator.vector")

createCommandLineArgumentFile = true
}
}

tasks.compileJava {
extensions.configure<CompileModuleOptions> {
addExports.putAll(
mapOf(
// TODO: Remove access to internal api
"javafx.controls/com.sun.javafx.scene.control" to "org.jabref",
"org.controlsfx.controls/impl.org.controlsfx.skin" to "org.jabref"
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"
)
)
}
}

Expand Down Expand Up @@ -286,7 +227,8 @@ jlink {
"zip-6",
"--no-header-files",
"--no-man-pages",
"--bind-services"
"--bind-services",
"--add-modules", "jdk.incubator.vector"
)

launcher {
Expand Down Expand Up @@ -489,3 +431,18 @@ if (OperatingSystem.current().isWindows) {
}
}
}

javaModuleTesting.whitebox(testing.suites["test"]) {
requires.add("org.junit.jupiter.api")
requires.add("org.junit.jupiter.params")
requires.add("org.mockito")
requires.add("org.jabref.testsupport")
}

tasks.test {
jvmArgs = listOf(
"--add-opens", "javafx.graphics/com.sun.javafx.application=org.testfx",
"--add-reads", "org.mockito=java.prefs",
"--add-reads", "org.mockito=javafx.scene",
)
}
5 changes: 3 additions & 2 deletions jabgui/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

// region JavaFX
requires javafx.base;
requires javafx.graphics;
requires javafx.controls;
requires javafx.web;
requires javafx.fxml;
requires javafx.graphics;
requires javafx.web;

requires com.tobiasdiez.easybind;

requires afterburner.fx;
Expand Down
Loading
Loading