diff --git a/src/main/java/org/openjfx/gradle/JavaFXModule.java b/src/main/java/org/openjfx/gradle/JavaFXModule.java index 353a96f..00079ce 100644 --- a/src/main/java/org/openjfx/gradle/JavaFXModule.java +++ b/src/main/java/org/openjfx/gradle/JavaFXModule.java @@ -42,16 +42,22 @@ public enum JavaFXModule { BASE, - GRAPHICS, - CONTROLS, - FXML, - MEDIA, - SWING, - WEB; + GRAPHICS(BASE), + CONTROLS(BASE, GRAPHICS), + FXML(BASE, GRAPHICS), + MEDIA(BASE, GRAPHICS), + SWING(BASE, GRAPHICS), + WEB(BASE, CONTROLS, GRAPHICS, MEDIA); static final String PREFIX_MODULE = "javafx."; private static final String PREFIX_ARTIFACT = "javafx-"; + private final List dependentModules; + + JavaFXModule(JavaFXModule...dependentModules) { + this.dependentModules = List.of(dependentModules); + } + public static Optional fromModuleName(String moduleName) { return Stream.of(JavaFXModule.values()) .filter(javaFXModule -> moduleName.equals(javaFXModule.getModuleName())) @@ -93,4 +99,8 @@ public static void validateModules(List moduleNames) { throw new GradleException("Found one or more invalid JavaFX module names: " + invalidModules); } } + + public List getDependentModules() { + return dependentModules; + } } diff --git a/src/main/java/org/openjfx/gradle/JavaFXOptions.java b/src/main/java/org/openjfx/gradle/JavaFXOptions.java index b4de550..b2c729d 100644 --- a/src/main/java/org/openjfx/gradle/JavaFXOptions.java +++ b/src/main/java/org/openjfx/gradle/JavaFXOptions.java @@ -43,12 +43,12 @@ import javax.inject.Inject; import java.io.File; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Stream; abstract public class JavaFXOptions { @@ -185,23 +185,29 @@ private void declareFXDependencies(String conf) { // This allows users to make multiple modifications to the 'configurations' list at arbitrary times during // build configuration. getConfigurationContainer().getByName(conf).withDependencies(dependencySet -> { - if (!List.of(configurations).contains(conf)) { - // configuration was removed: do nothing - return; - } - JavaFXModule.getJavaFXModules(this.modules).stream() - .sorted() - .forEach(javaFXModule -> { - if (customSDKArtifactRepository != null) { - dependencySet.add(getDependencies().create(Map.of("name", javaFXModule.getModuleName()))); - } else { - dependencySet.add(getDependencies().create( - MAVEN_JAVAFX_ARTIFACT_GROUP_ID + ":" - + javaFXModule.getArtifactName() + ":" - + getVersion() - )); - } - }); + if (!List.of(configurations).contains(conf)) { + // configuration was removed: do nothing + return; + } + + Set javaFXModules = JavaFXModule.getJavaFXModules(this.modules); + if (customSDKArtifactRepository == null) { + javaFXModules.stream().sorted().forEach(javaFXModule -> dependencySet.add(getDependencies().create( + MAVEN_JAVAFX_ARTIFACT_GROUP_ID + ":" + javaFXModule.getArtifactName() + ":" + getVersion() + ))); + } else { + // Use the list of dependencies of each module to also add direct dependencies for those. + // This is needed, because there is no information about transitive dependencies in the metadata + // of the modules (as there is no such metadata in the local sdk). + Stream javaFXModulesWithTransitives = Stream.concat( + javaFXModules.stream(), + javaFXModules.stream().flatMap(m -> m.getDependentModules().stream()) + ).distinct().sorted(); + + javaFXModulesWithTransitives.forEach(javaFXModule -> dependencySet.add(getDependencies().create( + Map.of("name", javaFXModule.getModuleName()) + ))); + } }); } diff --git a/test-project/local-sdk/build.gradle b/test-project/local-sdk/build.gradle index 9d07cda..c8ef160 100644 --- a/test-project/local-sdk/build.gradle +++ b/test-project/local-sdk/build.gradle @@ -12,6 +12,6 @@ application { } javafx { - modules = ['javafx.controls', 'javafx.base', 'javafx.graphics'] + modules = ['javafx.controls'] sdk = "javafx-sdk-17.0.8" }