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

#63 Add sdk extension #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
34 changes: 30 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,14 @@ For instance, the following configuration adds some VM options and a command lin
</plugin>
```

**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.

```
<properties>
Expand All @@ -172,6 +174,30 @@ all the required jars needs to be added as a separate dependency, like:
</dependencies>
```

Alternatively, while keeping the regular JavaFX dependencies,
the path to a local JavaFX SDK can be set:

```
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>
...
</dependencies>

<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>${javafx.plugin.version}</version>
<configuration>
<sdk>/path/to/javafx-sdk</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:
Expand Down
31 changes: 30 additions & 1 deletion src/main/java/org/openjfx/JavaFXBaseMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> classpathElements;
List<String> modulepathElements;
Map<String, JavaModuleDescriptor> pathElements;
Expand Down Expand Up @@ -314,13 +324,32 @@ private List<File> 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;
Expand Down