diff --git a/README.md b/README.md index 1f16934..9af4c50 100644 --- a/README.md +++ b/README.md @@ -148,12 +148,14 @@ For instance, the following configuration adds some VM options and a command lin ``` -**Note** +**Local SDK** -It is possible to use a local SDK instead of Maven Central. +It is possible to use a local SDK instead of Maven Central artifacts. This is helpful for developers trying to test a local build of OpenJFX. -Since transitive dependencies are not resolved, -all the required jars needs to be added as a separate dependency, like: + +One way to do it is using local dependencies. However, +since transitive dependencies are not resolved, +all the required jars need to be added as a separate dependency. ``` @@ -172,6 +174,30 @@ all the required jars needs to be added as a separate dependency, like: ``` +Alternatively, while keeping the regular JavaFX dependencies, +the path to a local JavaFX SDK can be set: + +``` + + + org.openjfx + javafx-controls + ${javafx.version} + + ... + + + + org.openjfx + javafx-maven-plugin + ${javafx.plugin.version} + + /path/to/javafx-sdk +... +``` + +and all the JavaFX dependencies (including transitive ones) will be replaced. + ### javafx:jlink options The same command line options for `jlink` can be set: diff --git a/src/main/java/org/openjfx/JavaFXBaseMojo.java b/src/main/java/org/openjfx/JavaFXBaseMojo.java index a50c0cf..fb986c9 100644 --- a/src/main/java/org/openjfx/JavaFXBaseMojo.java +++ b/src/main/java/org/openjfx/JavaFXBaseMojo.java @@ -55,6 +55,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Properties; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -156,6 +157,15 @@ abstract class JavaFXBaseMojo extends AbstractMojo { @Parameter(property = "javafx.includePathExceptionsInClasspath", defaultValue = "false") private boolean includePathExceptionsInClasspath; + /** + * Path to a local JavaFX SDK. + * + * When set to a valid path, the JavaFX jars found in this path + * will be used instead of the Maven Central ones + */ + @Parameter(property = "javafx.sdk") + private String sdk; + List classpathElements; List modulepathElements; Map pathElements; @@ -314,13 +324,32 @@ private List getCompileClasspathElements(MavenProject project) { } return compare; }) - .map(Artifact::getFile) + .map(this::getFileForArtifact) + .filter(Objects::nonNull) + .distinct() .collect(Collectors.toList())); return list.stream() .distinct() .collect(Collectors.toList()); } + private File getFileForArtifact(Artifact a) { + if (a == null || a.getArtifactId() == null) { + return null; + } + if (sdk == null) { + return a.getFile(); + } + Path jarPath = Paths.get(sdk, "lib", + a.getArtifactId().replace("-", ".") + ".jar"); + if (!Files.exists(jarPath)) { + getLog().warn("Path for jar " + a.getArtifactId() + " not found at " + jarPath + ".\n" + + "Using default Maven Central artifact instead."); + return a.getFile(); + } + return jarPath.toFile(); + } + void handleWorkingDirectory() throws MojoExecutionException { if (workingDirectory == null) { workingDirectory = basedir;