From a8d3185583898c60e31d8753d1d2d2bc6755bdbe Mon Sep 17 00:00:00 2001 From: Marco Collovati Date: Thu, 12 Sep 2024 11:16:28 +0200 Subject: [PATCH 1/2] fix: index optional dependencies (#172) Development (e.g. vaadin-dev-server) and optional (e.g. flow-react) dependencies must not be present in the Vaadin platform indexed, to prevent NoClassDefFound errors at runtime, for example when running a production build with dev-server excluded. This change adds a build step to index optional dependencies only if they are present in the project configuration. Part of #158 --- .../deployment/VaadinQuarkusProcessor.java | 73 ++++++++++++++++++- integration-tests/development/pom.xml | 8 ++ integration-tests/production/pom.xml | 8 ++ 3 files changed, 86 insertions(+), 3 deletions(-) diff --git a/deployment/src/main/java/com/vaadin/quarkus/deployment/VaadinQuarkusProcessor.java b/deployment/src/main/java/com/vaadin/quarkus/deployment/VaadinQuarkusProcessor.java index 3bbd1f2..16bc9b9 100644 --- a/deployment/src/main/java/com/vaadin/quarkus/deployment/VaadinQuarkusProcessor.java +++ b/deployment/src/main/java/com/vaadin/quarkus/deployment/VaadinQuarkusProcessor.java @@ -20,6 +20,9 @@ import java.util.Collection; import java.util.Objects; import java.util.Optional; +import java.util.Set; +import java.util.function.Predicate; +import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -29,18 +32,23 @@ import io.quarkus.arc.deployment.ContextRegistrationPhaseBuildItem; import io.quarkus.arc.deployment.ContextRegistrationPhaseBuildItem.ContextConfiguratorBuildItem; import io.quarkus.arc.deployment.CustomScopeBuildItem; +import io.quarkus.arc.deployment.IgnoreSplitPackageBuildItem; +import io.quarkus.bootstrap.model.ApplicationModel; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; import io.quarkus.deployment.annotations.ExecutionTime; import io.quarkus.deployment.annotations.Record; import io.quarkus.deployment.builditem.CombinedIndexBuildItem; import io.quarkus.deployment.builditem.FeatureBuildItem; +import io.quarkus.deployment.builditem.IndexDependencyBuildItem; +import io.quarkus.deployment.builditem.RemovedResourceBuildItem; +import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem; +import io.quarkus.maven.dependency.ArtifactKey; import io.quarkus.undertow.deployment.ServletBuildItem; import io.quarkus.undertow.deployment.ServletDeploymentManagerBuildItem; import io.quarkus.vertx.http.deployment.FilterBuildItem; import io.quarkus.websockets.client.deployment.ServerWebSocketContainerBuildItem; import io.quarkus.websockets.client.deployment.WebSocketDeploymentInfoBuildItem; -import org.atmosphere.cpr.ApplicationConfig; import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; @@ -83,6 +91,66 @@ FeatureBuildItem feature() { return new FeatureBuildItem(FEATURE); } + @BuildStep + void indexOptionalVaadinDependencies( + BuildProducer producer) { + // Optional dependencies + producer.produce( + new IndexDependencyBuildItem("com.vaadin", "flow-react")); + producer.produce(new IndexDependencyBuildItem("com.vaadin", + "flow-polymer-template")); + + // Development dependencies + producer.produce(new IndexDependencyBuildItem("com.vaadin", + "vaadin-dev-server")); + producer.produce(new IndexDependencyBuildItem("com.vaadin", "copilot")); + producer.produce( + new IndexDependencyBuildItem("com.vaadin", "ui-tests")); + } + + /* + * Removes vaadin-core-jandex artifact, if vaadin-jandex is also present + */ + @BuildStep + void removeUnusedJandexIndex(CurateOutcomeBuildItem curateOutcome, + BuildProducer removedResourceProducer, + BuildProducer ignoreSplitPackage) { + Predicate isVaadinJandex = Pattern + .compile("vaadin(-core)?-jandex").asMatchPredicate(); + ApplicationModel applicationModel = curateOutcome.getApplicationModel(); + Set vaadinIndexes = applicationModel.getDependencies().stream() + .filter(archive -> "com.vaadin" + .equals(archive.getKey().getGroupId()) + && isVaadinJandex + .test(archive.getKey().getArtifactId())) + .map(archive -> archive.getKey().toGacString()) + .collect(Collectors.toSet()); + if (vaadinIndexes.size() > 1) { + ArtifactKey artifactKey = ArtifactKey.of("com.vaadin", + "vaadin-core-jandex", null, "jar"); + // To prevent the vaadin-core-index to be indexed, it should add to + // the removed resources, but producing a RemovedResourceBuildItem + // does not prevent the split package processor to log all classes + // present in both vaadin-jandex and vaadin-core-jandex The + // removedResources map in ApplicationModel is computed before the + // SplitPackageProcessor and it is mutable, but the javadocs don't + // specify if updating it is allowed or not. To prevent issues in + // the future, try to put the artifact in the collection, but + // fallback to producing a RemovedResourceBuildItem and a + // IgnoreSplitPackageBuildItem to prevent the verbose and useless + // log. + try { + applicationModel.getRemovedResources().put(artifactKey, + Set.of()); + } catch (Exception ex) { + removedResourceProducer.produce( + new RemovedResourceBuildItem(artifactKey, Set.of())); + ignoreSplitPackage.produce(new IgnoreSplitPackageBuildItem( + Set.of("com.vaadin.*"))); + } + } + } + @BuildStep public void build( final BuildProducer additionalBeanProducer, @@ -145,8 +213,7 @@ void mapVaadinServletPaths(final BeanArchiveIndexBuildItem beanArchiveIndex, .builder(QuarkusVaadinServlet.class.getName(), QuarkusVaadinServlet.class.getName()) .addMapping("/*").setAsyncSupported(true) - .setLoadOnStartup(1) - .build()); + .setLoadOnStartup(1).build()); } } diff --git a/integration-tests/development/pom.xml b/integration-tests/development/pom.xml index 840d5fe..0563b63 100644 --- a/integration-tests/development/pom.xml +++ b/integration-tests/development/pom.xml @@ -30,6 +30,14 @@ com.vaadin flow-html-components + + com.vaadin + flow-dnd + + + com.vaadin + flow-react + com.vaadin vaadin-dev-server diff --git a/integration-tests/production/pom.xml b/integration-tests/production/pom.xml index a48d2ea..eadcb23 100644 --- a/integration-tests/production/pom.xml +++ b/integration-tests/production/pom.xml @@ -30,6 +30,14 @@ com.vaadin flow-html-components + + com.vaadin + flow-dnd + + + com.vaadin + flow-react + com.vaadin reusable-theme From 797c11cb0f7efdf2d9d90244c66a0d1bb13871ca Mon Sep 17 00:00:00 2001 From: Marco Collovati Date: Thu, 12 Sep 2024 12:08:38 +0200 Subject: [PATCH 2/2] upgrade Quarkus to the minimum supported version Branch 2.0 of the add-on supports Quarkus 3.2 and 3.8. --- integration-tests/pom.xml | 14 ++++++++++++++ pom.xml | 14 +++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 87d87c8..51280d5 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -60,6 +60,20 @@ 31.0.1-jre test + + + + net.java.dev.jna + jna + 5.14.0 + test + + + net.java.dev.jna + jna-platform + 5.14.0 + test + diff --git a/pom.xml b/pom.xml index 8bccd17..4963aed 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ true 24.4-SNAPSHOT - 3.0.1.Final + 3.2.12.Final 1.16.0-alpha 1.16.0 @@ -102,16 +102,16 @@ import - io.quarkus - quarkus-bom - ${quarkus.version} + com.vaadin + flow-bom + ${vaadin.flow.version} pom import - com.vaadin - flow-bom - ${vaadin.flow.version} + io.quarkus + quarkus-bom + ${quarkus.version} pom import