From 2a11bf05f12ee1c1a59d7f4f6a97da17039e9943 Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Tue, 19 Sep 2023 18:10:16 +0530 Subject: [PATCH 1/3] use Gradle's built-in Java Module System support --- build.gradle | 47 ++++++---------- gradle/wrapper/gradle-wrapper.properties | 4 +- settings.gradle | 17 ++++++ .../gradle/attach/AttachConfiguration.java | 17 ++++-- .../gradle/tasks/NativeRunAgentTask.java | 53 ++----------------- 5 files changed, 54 insertions(+), 84 deletions(-) diff --git a/build.gradle b/build.gradle index 88ed60e..f2573bd 100644 --- a/build.gradle +++ b/build.gradle @@ -1,22 +1,19 @@ plugins { - id 'java-gradle-plugin' - id 'com.github.hierynomus.license' version '0.15.0' - id 'com.gradle.plugin-publish' version '1.0.0-rc-2' - id 'com.github.ben-manes.versions' version '0.27.0' - id 'maven-publish' + id 'com.gradle.plugin-publish' version '1.2.1' + id 'com.github.ben-manes.versions' version '0.47.0' + id 'com.github.hierynomus.license' version '0.16.1' } group 'com.gluonhq' version '1.0.21-SNAPSHOT' -sourceCompatibility = 11 -targetCompatibility = 11 +java { + toolchain.languageVersion = JavaLanguageVersion.of(11) +} repositories { mavenCentral() - maven { - url "https://plugins.gradle.org/m2/" - } + gradlePluginPortal() maven { url "https://oss.sonatype.org/content/repositories/snapshots" } @@ -27,7 +24,7 @@ dependencies { testImplementation gradleTestKit() implementation 'com.gluonhq:substrate:0.0.61-SNAPSHOT' - implementation 'org.openjfx:javafx-plugin:0.0.10' + implementation 'org.openjfx:javafx-plugin:0.1.0' } gradlePlugin { @@ -37,32 +34,22 @@ gradlePlugin { displayName = 'GluonFX Plugin' description = 'GluonFX plugin allows to run JavaFX application on the JVM or to create their native images.' implementationClass = 'com.gluonhq.gradle.GluonFXPlugin' + website = 'https://github.com/gluonhq/gluonfx-gradle-plugin' + vcsUrl = 'https://github.com/gluonhq/gluonfx-gradle-plugin' + tags.set([ 'java', 'javafx', 'gluon', 'client', 'substrate', 'graalvm', 'aot' ]) } } } -pluginBundle { - website = 'https://github.com/gluonhq/gluonfx-gradle-plugin' - vcsUrl = 'https://github.com/gluonhq/gluonfx-gradle-plugin' - tags = [ 'java', 'javafx', 'gluon', 'client', 'substrate', 'graalvm', 'aot' ] -} - publishing { - publications { - maven(MavenPublication) { - groupId = project.group - artifactId = 'gluonfx-gradle-plugin' - version = project.version - } - } repositories { maven { - if (project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword')) { - credentials { - username project.property('sonatypeUsername') - password project.property('sonatypePassword') - } - url = 'https://oss.sonatype.org/content/repositories/snapshots/' + url = "https://oss.sonatype.org/content/repositories/snapshots/" + def sonatypeUsername = providers.gradleProperty('sonatypeUsername') + def sonatypePassword = providers.gradleProperty('sonatypePassword') + if (sonatypeUsername.isPresent() && sonatypePassword.isPresent()) { + username = sonatypeUsername.get() + password = sonatypePassword.get() } } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 874e110..d68b34f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,6 @@ distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionSha256Sum=038794feef1f4745c6347107b6726279d1c824f3fc634b60f86ace1e9fbd1768 -distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +networkTimeout=10000 +validateDistributionUrl=true \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 5d499fd..2e5ec23 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,18 @@ +pluginManagement { + repositories { + gradlePluginPortal() + } +} + +plugins { + id 'com.gradle.enterprise' version '3.14.1' +} + +gradleEnterprise { + buildScan { + termsOfServiceUrl = 'https://gradle.com/terms-of-service' + termsOfServiceAgree = 'yes' + } +} + rootProject.name = 'gluonfx-gradle-plugin' diff --git a/src/main/java/com/gluonhq/gradle/attach/AttachConfiguration.java b/src/main/java/com/gluonhq/gradle/attach/AttachConfiguration.java index b9051a9..c4ff4a9 100644 --- a/src/main/java/com/gluonhq/gradle/attach/AttachConfiguration.java +++ b/src/main/java/com/gluonhq/gradle/attach/AttachConfiguration.java @@ -1,7 +1,7 @@ /* * BSD 3-Clause License * - * Copyright (c) 2018, 2021, Gluon Software + * Copyright (c) 2018, 2023, Gluon Software * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -44,6 +44,7 @@ import com.gluonhq.gradle.ClientExtension; import com.gluonhq.substrate.Constants; +import org.gradle.api.artifacts.ModuleDependency; public class AttachConfiguration { private static final String DEPENDENCY_GROUP = "com.gluonhq.attach"; @@ -126,7 +127,14 @@ private void applyConfiguration() { if (services != null && !services.isEmpty()) { services.stream() .map(asd -> generateDependencyNotation(asd, target)) - .forEach(depNotion -> project.getDependencies().add(configName, depNotion)); + .forEach(depNotion -> { + ModuleDependency dep = (ModuleDependency) project.getDependencies().add(configName, depNotion); + if (dep != null) { + dep.exclude(Map.of("group", "org.openjfx", "module", "*")); + } + }); + + // Also add util artifact if any other artifact added Map utilDependencyNotationMap = new HashMap<>(); @@ -139,7 +147,10 @@ private void applyConfiguration() { Constants.PROFILE_IOS : target; utilDependencyNotationMap.put("classifier", utilTarget); } - project.getDependencies().add(configName, utilDependencyNotationMap); + ModuleDependency dep = (ModuleDependency) project.getDependencies().add(configName, utilDependencyNotationMap); + if (dep != null) { + dep.exclude(Map.of("group", "org.openjfx", "module", "*")); + } } lastAppliedConfiguration = configuration; diff --git a/src/main/java/com/gluonhq/gradle/tasks/NativeRunAgentTask.java b/src/main/java/com/gluonhq/gradle/tasks/NativeRunAgentTask.java index 8001ab6..da31dcc 100644 --- a/src/main/java/com/gluonhq/gradle/tasks/NativeRunAgentTask.java +++ b/src/main/java/com/gluonhq/gradle/tasks/NativeRunAgentTask.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, 2022, Gluon + * Copyright (c) 2021, 2023, Gluon * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,14 +33,9 @@ import org.gradle.api.GradleException; import org.gradle.api.Project; import org.gradle.api.Task; -import org.gradle.api.file.FileCollection; import org.gradle.api.plugins.ApplicationPlugin; import org.gradle.api.tasks.JavaExec; import org.gradle.api.tasks.TaskAction; -import org.gradle.util.GradleVersion; -import org.openjfx.gradle.JavaFXModule; -import org.openjfx.gradle.JavaFXOptions; -import org.openjfx.gradle.JavaFXPlatform; import javax.inject.Inject; import java.io.BufferedWriter; @@ -53,12 +48,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.TreeSet; public class NativeRunAgentTask extends NativeBaseTask { - private static final String CONFIG_JAVAFX_RUN_TASK = "configJavafxRun"; - private static final String AGENTLIB_NATIVE_IMAGE_AGENT_STRING = "-agentlib:native-image-agent=access-filter-file=src/main/resources/META-INF/native-image/filter-file.json,config-merge-dir=src/main/resources/META-INF/native-image"; @@ -75,12 +67,6 @@ public class NativeRunAgentTask extends NativeBaseTask { public NativeRunAgentTask(Project project) { super(project); clientExtension = project.getExtensions().getByType(ClientExtension.class); - - Task javafxRun = project.getTasks().findByName(CONFIG_JAVAFX_RUN_TASK); - if (javafxRun == null) { - throw new GradleException("javafxplugin:" + CONFIG_JAVAFX_RUN_TASK + " task not found."); - } - this.dependsOn(javafxRun.getPath()); } @TaskAction @@ -118,38 +104,12 @@ public void action() { throw new GradleException("Run task not found."); } - JavaFXOptions javaFXOptions = project.getExtensions().getByType(JavaFXOptions.class); - var definedJavaFXModuleNames = new TreeSet<>(javaFXOptions.getModules()); - if (definedJavaFXModuleNames.isEmpty()) { - throw new GradleException("No JavaFX modules found."); - } - final FileCollection classpathWithoutJavaFXJars = execTask.getClasspath().filter( - jar -> Arrays.stream(JavaFXModule.values()).noneMatch(javaFXModule -> - jar.getName().contains(javaFXModule.getArtifactName())) - ); - final FileCollection javaFXPlatformJars = execTask.getClasspath().filter(jar -> - isJavaFXJar(jar, javaFXOptions.getPlatform())); - - // Remove all JavaFX jars from classpath - execTask.setClasspath(classpathWithoutJavaFXJars); - - // Define JVM args for command line - var javaFXModuleJvmArgs = List.of("--module-path", javaFXPlatformJars.getAsPath()); - var jvmArgs = new ArrayList<>(javaFXModuleJvmArgs); - jvmArgs.add("--add-modules"); - jvmArgs.add(String.join(",", definedJavaFXModuleNames)); - if (GradleVersion.current().compareTo(GradleVersion.version("6.6")) < 0) { - // Include classpath as JVM arg for Gradle versions lower than 6.6 - jvmArgs.add("-cp"); - jvmArgs.add(classpathWithoutJavaFXJars.getAsPath()); - } - // set java_home execTask.executable(Path.of(graalVMHome.toString(), "bin", "java").toString()); // set jvmargs - execTask.getJvmArgs().add(AGENTLIB_NATIVE_IMAGE_AGENT_STRING); - execTask.getJvmArgs().addAll(jvmArgs); + var jvmArgs = List.of(AGENTLIB_NATIVE_IMAGE_AGENT_STRING); + execTask.getJvmArgumentProviders().add(() -> jvmArgs); // run execTask.exec(); @@ -191,11 +151,4 @@ private void createFilterFile(String agentFilter) throws IOException { bw.write("}\n"); } } - - private static boolean isJavaFXJar(File jar, JavaFXPlatform platform) { - return jar.isFile() && - Arrays.stream(JavaFXModule.values()).anyMatch(javaFXModule -> - javaFXModule.compareJarFileName(platform, jar.getName()) || - javaFXModule.getModuleJarFileName().equals(jar.getName())); - } } From 9014a1f332ba006baffcb014350b7d2c1550f9aa Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Wed, 20 Sep 2023 08:49:42 +0530 Subject: [PATCH 2/3] remove whitespace --- .../java/com/gluonhq/gradle/attach/AttachConfiguration.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/com/gluonhq/gradle/attach/AttachConfiguration.java b/src/main/java/com/gluonhq/gradle/attach/AttachConfiguration.java index c4ff4a9..aa35dcc 100644 --- a/src/main/java/com/gluonhq/gradle/attach/AttachConfiguration.java +++ b/src/main/java/com/gluonhq/gradle/attach/AttachConfiguration.java @@ -134,8 +134,6 @@ private void applyConfiguration() { } }); - - // Also add util artifact if any other artifact added Map utilDependencyNotationMap = new HashMap<>(); utilDependencyNotationMap.put("group", DEPENDENCY_GROUP); From edbb92d550a2f765195d11c756302f9ff381a292 Mon Sep 17 00:00:00 2001 From: Abhinay Agarwal Date: Wed, 20 Sep 2023 09:04:26 +0530 Subject: [PATCH 3/3] fix checksum --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d68b34f..0836bd3 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,7 +2,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionSha256Sum=038794feef1f4745c6347107b6726279d1c824f3fc634b60f86ace1e9fbd1768 +distributionSha256Sum=591855b517fc635b9e04de1d05d5e76ada3f89f5fc76f87978d1b245b4f69225 distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip networkTimeout=10000 validateDistributionUrl=true \ No newline at end of file