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

Fix gradle devui NoClassDefFound #46680

Merged
merged 1 commit into from
Mar 11, 2025

Conversation

Malandril
Copy link
Contributor

@Malandril Malandril commented Mar 9, 2025

This PR fixes #45112.
It fixes the devui NoClassDefFound errors triggered when using the gradle build tool in dev mode and disables the Add extension button.

When #43840 was merged it allowed to dynamically add new extensions using the dev ui but it doesn't work nicelly with gradle projects:

  1. It did'nt correctly identify the path of the project with gradle as the current working dir in gradle retrieved here
    Path projectRoot = Paths.get(System.getProperty("user.dir")).toAbsolutePath().normalize();
    will be in the build/classes/java/main directory and not the project directory and as such will always detect a gradle project as being a maven project
  2. In the gradle dev mode task we only explicitly add parentFirstDependencies and as such the maven resolver dependencies are absent from the classpath
    if (file.exists() && configuredParentFirst.contains(artifact.getKey())
  3. One all the above is resolved, the io.quarkus.devtools.project.buildfile.GenericGradleBuildFile extensionManager cannot neither list nor add any new extension as it doesn't work outside of the gradle plugin.

@quarkus-bot quarkus-bot bot added area/core area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins area/gradle Gradle area/vertx labels Mar 9, 2025
@@ -465,11 +464,14 @@ private DevModeCommandLine newLauncher(final AnalyticsService analyticsService)
builder.extensionDevModeConfig(appModel.getExtensionDevModeConfig())
.extensionDevModeJvmOptionFilter(extensionJvmOptions);

builder.jvmArgs("-Dgradle.project.path="
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only way I found to findthe correct gradle project path independent of build language or sourceSet name is to send it as a system property

analyticsService.sendAnalytics(
DEV_MODE,
appModel,
Map.of(GRADLE_VERSION, getProject().getGradle().getGradleVersion()),
getProject().getBuildDir().getAbsoluteFile());
getProject().getLayout().getBuildDirectory().getAsFile().get());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getBuildDir() is deprecated

@@ -150,7 +150,9 @@ export class QwcContinuousTesting extends QwcHotReloadElement {

_cancelObservers(){
this._streamStateObserver.cancel();
this._streamResultsObserver.cancel();
if(this._streamResultsObserver){
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was undefined when switching tabs without running tests

@aloubyansky
Copy link
Member

@Malandril thanks a lot for looking into this. Perhaps try

diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java
index 44457c4fc2..6558f19e77 100644
--- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java
+++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/tasks/QuarkusDev.java
@@ -465,11 +465,14 @@ private DevModeCommandLine newLauncher(final AnalyticsService analyticsService)
         builder.extensionDevModeConfig(appModel.getExtensionDevModeConfig())
                 .extensionDevModeJvmOptionFilter(extensionJvmOptions);
 
+        builder.jvmArgs(
+                "-Dgradle.project.path=" + getProject().getLayout().getProjectDirectory().getAsFile().getAbsolutePath());
+
         analyticsService.sendAnalytics(
                 DEV_MODE,
                 appModel,
                 Map.of(GRADLE_VERSION, getProject().getGradle().getGradleVersion()),
-                getProject().getBuildDir().getAbsoluteFile());
+                getProject().getLayout().getBuildDirectory().getAsFile().get());
 
         final Set<ArtifactKey> projectDependencies = new HashSet<>();
         for (ResolvedDependency localDep : DependenciesFilter.getReloadableModules(appModel)) {
@@ -562,6 +565,7 @@ private void addQuarkusDevModeDeps(DevModeCommandLineBuilder builder, Applicatio
                         configuration.setCanBeConsumed(false);
                         configuration.extendsFrom(platformConfig);
                         configuration.getDependencies().add(getQuarkusGradleBootstrapResolver());
+                        configuration.getDependencies().add(getQuarkusMavenBootstrapResolver());
                         configuration.getDependencies().add(getQuarkusCoreDeployment(appModel));
                     });
             devModeDependencyConfiguration = getProject().getConfigurations()
@@ -585,7 +589,15 @@ private void addQuarkusDevModeDeps(DevModeCommandLineBuilder builder, Applicatio
     }
 
     private Dependency getQuarkusGradleBootstrapResolver() {
-        final String pomPropsPath = "META-INF/maven/io.quarkus/quarkus-bootstrap-gradle-resolver/pom.properties";
+        return getQuarkusBootstrapResolver("quarkus-bootstrap-gradle-resolver");
+    }
+
+    private Dependency getQuarkusMavenBootstrapResolver() {
+        return getQuarkusBootstrapResolver("quarkus-bootstrap-maven-resolver");
+    }
+
+    private Dependency getQuarkusBootstrapResolver(String artifactId) {
+        final String pomPropsPath = "META-INF/maven/io.quarkus/" + artifactId + "/pom.properties";

to add the Maven resolver classes for the extension catalog resolver.

@Malandril Malandril force-pushed the bugfix/gradle_ext_resolver branch from 305e64d to 45c9998 Compare March 10, 2025 21:32
@Malandril
Copy link
Contributor Author

Thanks @aloubyansky its a lot simpler

Copy link

quarkus-bot bot commented Mar 11, 2025

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit 45c9998.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.


Flaky tests - Develocity

⚙️ JVM Tests - JDK 17 Windows

📦 extensions/micrometer-opentelemetry/deployment

io.quarkus.micrometer.opentelemetry.deployment.compatibility.MicrometerTimedInterceptorTest.testTimeMethod_Uni - History

  • Stream has no elements - java.lang.IllegalArgumentException
java.lang.IllegalArgumentException: Stream has no elements
	at io.quarkus.micrometer.opentelemetry.deployment.common.MetricDataFilter.lambda$lastReading$2(MetricDataFilter.java:213)
	at java.base/java.util.Optional.orElseThrow(Optional.java:403)
	at io.quarkus.micrometer.opentelemetry.deployment.common.MetricDataFilter.lastReading(MetricDataFilter.java:213)
	at io.quarkus.micrometer.opentelemetry.deployment.common.MetricDataFilter.lastReadingDataPoint(MetricDataFilter.java:231)
	at io.quarkus.micrometer.opentelemetry.deployment.compatibility.MicrometerTimedInterceptorTest.testTimeMethod_Uni(MicrometerTimedInterceptorTest.java:174)
	at java.base/java.lang.reflect.Method.invoke(Method.java:569)
	at io.quarkus.test.QuarkusUnitTest.runExtensionMethod(QuarkusUnitTest.java:521)

Copy link
Member

@aloubyansky aloubyansky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Malandril thanks a lot!

@phillip-kruger the change look good to me. Are you ok with it as well?

@phillip-kruger
Copy link
Member

Yes

@aloubyansky aloubyansky merged commit 99bdb00 into quarkusio:main Mar 11, 2025
58 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.21 - main milestone Mar 11, 2025
@gsmet gsmet modified the milestones: 3.21 - main, 3.19.3 Mar 11, 2025
@Malandril Malandril deleted the bugfix/gradle_ext_resolver branch March 11, 2025 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins area/gradle Gradle area/vertx kind/bugfix triage/flaky-test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Exception about missing maven classes when opening the dev-ui (gradle based project)
4 participants