From 7113affd7ef51bd315a08f7c8608a907f63e97fb Mon Sep 17 00:00:00 2001 From: "jose.pereda" Date: Fri, 3 Sep 2021 11:43:11 +0200 Subject: [PATCH] Add AOT jars with internal version and exclude their platform dependencies --- src/main/java/com/gluonhq/NativeBaseMojo.java | 7 ++++-- .../gluonhq/utils/MavenArtifactResolver.java | 23 +++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gluonhq/NativeBaseMojo.java b/src/main/java/com/gluonhq/NativeBaseMojo.java index 3b993ca..2ebd59e 100644 --- a/src/main/java/com/gluonhq/NativeBaseMojo.java +++ b/src/main/java/com/gluonhq/NativeBaseMojo.java @@ -50,6 +50,7 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.graph.DependencyFilter; import java.io.File; import java.io.IOException; @@ -256,9 +257,11 @@ private List getClasspathElements(MavenProject project) { project.getArtifacts().stream() .filter(a -> "org.openjfx".equals(a.getGroupId()) && a.getClassifier() != null) .map(a -> new DefaultArtifact(a.getGroupId(), a.getArtifactId(), - Constants.WEB_AOT_CLASSIFIER, "jar", a.getVersion())) + Constants.WEB_AOT_CLASSIFIER, "jar", Constants.DEFAULT_JAVAFX_JS_SDK_VERSION)) .flatMap(a -> { - Set resolve = MavenArtifactResolver.getInstance().resolve(a); + DependencyFilter exclusions = (node, parents) -> + !node.getArtifact().getClassifier().equals(Constants.WEB_AOT_CLASSIFIER); + Set resolve = MavenArtifactResolver.getInstance().resolve(a, exclusions); if (resolve == null) { return Stream.empty(); } diff --git a/src/main/java/com/gluonhq/utils/MavenArtifactResolver.java b/src/main/java/com/gluonhq/utils/MavenArtifactResolver.java index a47405c..46bc9b7 100644 --- a/src/main/java/com/gluonhq/utils/MavenArtifactResolver.java +++ b/src/main/java/com/gluonhq/utils/MavenArtifactResolver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, Gluon + * Copyright (c) 2019, 2021, Gluon * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -178,6 +178,18 @@ private DefaultRepositorySystemSession createRepositorySystemSession(RepositoryS * @return a set of existing artifacts */ public Set resolve(Artifact artifact) { + return resolve(artifact, null); + } + + /** + * Finds a set of existing artifacts for a created artifact out of on some coordinates and + * classifier + * + * @param artifact the created artifact + * @param exclusionsFilter a filter that identifies artifacts that will be excluded, it can be null + * @return a set of existing artifacts + */ + public Set resolve(Artifact artifact, DependencyFilter exclusionsFilter) { ArtifactResult resolvedArtifact; try { List artifactRequests = Arrays.asList( @@ -196,7 +208,14 @@ public Set resolve(Artifact artifact) { collectRequest.setRoot(new Dependency(resolvedArtifact.getArtifact(), JavaScopes.COMPILE)); collectRequest.setRepositories(remoteRepositories); - DependencyFilter classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE); + DependencyFilter classpathFilter; + if (exclusionsFilter != null) { + classpathFilter = DependencyFilterUtils.andFilter( + DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE), + DependencyFilterUtils.notFilter(exclusionsFilter)); + } else { + classpathFilter = DependencyFilterUtils.classpathFilter(JavaScopes.COMPILE); + } DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, classpathFilter); List artifactResults;