Skip to content
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

Do not automatically apply the gradle-modules-plugin if the project uses a Gradle version >= 6.4. #96

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ To use the plugin, apply the following two steps:
}
apply(plugin = "org.openjfx.javafxplugin")


### 2. Specify JavaFX modules

Specify all the JavaFX modules that your project uses:
Expand Down Expand Up @@ -136,4 +135,32 @@ Setting a valid path to the local JavaFX SDK will take precedence:
javafx {
sdk = "/path/to/javafx-sdk"
modules("javafx.controls", "javafx.fxml")
}
}

### 6. Native module support (Gradle 7.0 and above)

Since Gradle 7.0, Gradle has native support for Java modules. This plugin adds
the [gradle-modules-plugin](https://github.com/java9-modularity/gradle-modules-plugin) by default. If you would like to use Gradle's native
module support instead, you can disable the modules plugin by specifying:

**Groovy/Kotlin**

javafx {
useNativeModuleSupport = true;
}


Note that in Gradle versions 6.4 - 6.9, you have to explicitly enable native
module support:

**Groovy/Kotlin**

java {
modularity.inferModulePath.set(true)
}

In Gradle versions below 6.4, setting the `useNativeModuleSupport` option to `true`
will have no effect.



16 changes: 16 additions & 0 deletions src/main/java/org/openjfx/gradle/JavaFXOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import org.gradle.api.Project;
import org.gradle.api.artifacts.repositories.FlatDirectoryArtifactRepository;
import org.gradle.util.VersionNumber;

import java.io.File;
import java.util.ArrayList;
Expand All @@ -54,6 +55,7 @@ public class JavaFXOptions {
private String lastUpdatedConfiguration;
private List<String> modules = new ArrayList<>();
private FlatDirectoryArtifactRepository customSDKArtifactRepository;
private boolean useNativeModuleSupport = true;

public JavaFXOptions(Project project) {
this.project = project;
Expand Down Expand Up @@ -113,6 +115,14 @@ public void modules(String...moduleNames) {
setModules(List.of(moduleNames));
}

public boolean isUseNativeModuleSupport() {
return useNativeModuleSupport && isGradleVersionWithNativeModuleSupport();
}

public void setUseNativeModuleSupport(boolean useNativeModuleSupport) {
this.useNativeModuleSupport = useNativeModuleSupport;
}

private void updateJavaFXDependencies() {
clearJavaFXDependencies();

Expand Down Expand Up @@ -159,4 +169,10 @@ private void clearJavaFXDependencies() {
.removeIf(dependency -> MAVEN_JAVAFX_ARTIFACT_GROUP_ID.equals(dependency.getGroup()));
}
}

private boolean isGradleVersionWithNativeModuleSupport() {
VersionNumber thisVersionNumber = VersionNumber.parse(project.getGradle().getGradleVersion());
VersionNumber lowestVersionNumberWithJavaFXSupport = VersionNumber.parse("6.4-rc-1");
return thisVersionNumber.compareTo(lowestVersionNumberWithJavaFXSupport) >= 0;
}
}
11 changes: 9 additions & 2 deletions src/main/java/org/openjfx/gradle/JavaFXPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.google.gradle.osdetector.OsDetectorPlugin;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPlugin;
import org.javamodularity.moduleplugin.ModuleSystemPlugin;
import org.openjfx.gradle.tasks.ExecTask;

Expand All @@ -40,10 +41,16 @@ public class JavaFXPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
project.getPlugins().apply(OsDetectorPlugin.class);
project.getPlugins().apply(ModuleSystemPlugin.class);

project.getExtensions().create("javafx", JavaFXOptions.class, project);
JavaFXOptions options = project.getExtensions().create("javafx", JavaFXOptions.class, project);

if (options.isUseNativeModuleSupport()) {
project.getPlugins().apply(JavaPlugin.class);
} else {
project.getPlugins().apply(ModuleSystemPlugin.class);
}

project.getTasks().create("configJavafxRun", ExecTask.class, project);
}

}
4 changes: 4 additions & 0 deletions src/main/java/org/openjfx/gradle/tasks/ExecTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public void action() {
// Remove empty JavaFX jars from classpath
execTask.setClasspath(classpathWithoutJavaFXJars.plus(javaFXPlatformJars));
definedJavaFXModuleNames.forEach(javaFXModule -> moduleOptions.getAddModules().add(javaFXModule));
} else if (javaFXOptions.isUseNativeModuleSupport()) {
LOGGER.info("Plugin configured to use native module support.");
// Remove empty JavaFX jars from classpath
execTask.setClasspath(classpathWithoutJavaFXJars.plus(javaFXPlatformJars));
} else {
LOGGER.info("Non-modular JavaFX application found");
// Remove all JavaFX jars from classpath
Expand Down