diff --git a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/QuarkusPlugin.java b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/QuarkusPlugin.java index 913565876bfe2..b2fb4d78493e2 100644 --- a/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/QuarkusPlugin.java +++ b/devtools/gradle/gradle-application-plugin/src/main/java/io/quarkus/gradle/QuarkusPlugin.java @@ -20,6 +20,7 @@ import org.gradle.api.artifacts.Configuration; import org.gradle.api.artifacts.ConfigurationContainer; import org.gradle.api.artifacts.ProjectDependency; +import org.gradle.api.artifacts.ResolvedArtifact; import org.gradle.api.plugins.BasePlugin; import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.plugins.JavaPluginConvention; @@ -256,13 +257,6 @@ private void registerConditionalDependencies(Project project) { .declareConditionalDependencies(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME); deploymentClasspathBuilder.createBuildClasspath(implementationExtensions, JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME); - // enable the Panache annotation processor on the classpath, if it's found among the dependencies - for (ExtensionDependency extension : implementationExtensions) { - if ("quarkus-panache-common".equals(extension.getName()) && "io.quarkus".equals(extension.getGroup())) { - project.getDependencies().add(JavaPlugin.ANNOTATION_PROCESSOR_CONFIGURATION_NAME, - extension.asDependencyNotation()); - } - } }); project.getConfigurations().getByName(DEV_MODE_CONFIGURATION_NAME).getIncoming().beforeResolve((devDependencies) -> { Set devModeExtensions = conditionalDependenciesEnabler @@ -276,6 +270,21 @@ private void registerConditionalDependencies(Project project) { deploymentClasspathBuilder.createBuildClasspath(testExtensions, JavaPlugin.TEST_IMPLEMENTATION_CONFIGURATION_NAME); }); + project.getConfigurations().getByName(JavaPlugin.ANNOTATION_PROCESSOR_CONFIGURATION_NAME).getIncoming() + .beforeResolve(annotationProcessors -> { + Set compileClasspathArtifacts = project.getConfigurations() + .getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME).getResolvedConfiguration() + .getResolvedArtifacts(); + + // enable the Panache annotation processor on the classpath, if it's found among the dependencies + for (ResolvedArtifact artifact : compileClasspathArtifacts) { + if ("quarkus-panache-common".equals(artifact.getName()) + && "io.quarkus".equals(artifact.getModuleVersion().getId().getGroup())) { + project.getDependencies().add(JavaPlugin.ANNOTATION_PROCESSOR_CONFIGURATION_NAME, + "io.quarkus:quarkus-panache-common:" + artifact.getModuleVersion().getId().getVersion()); + } + } + }); } private Set getSourcesParents(SourceSet mainSourceSet) { diff --git a/integration-tests/gradle/src/main/resources/annotation-processor-simple-module/build.gradle b/integration-tests/gradle/src/main/resources/annotation-processor-simple-module/build.gradle index 7380907644ca8..95fcb396d04cb 100644 --- a/integration-tests/gradle/src/main/resources/annotation-processor-simple-module/build.gradle +++ b/integration-tests/gradle/src/main/resources/annotation-processor-simple-module/build.gradle @@ -13,6 +13,7 @@ test { } repositories { + mavenCentral() if (System.properties.containsKey('maven.repo.local')) { maven { url System.properties.get('maven.repo.local') @@ -20,7 +21,6 @@ repositories { } else { mavenLocal() } - mavenCentral() } dependencies { @@ -28,6 +28,7 @@ dependencies { implementation 'io.quarkus:quarkus-resteasy' implementation 'io.quarkus:quarkus-resteasy-jackson' implementation "org.mapstruct:mapstruct:${mapstructVersion}" + implementation 'io.quarkus:quarkus-hibernate-orm-panache' annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}" diff --git a/integration-tests/gradle/src/test/java/io/quarkus/gradle/AnnotationProcessorSimpleModuleTest.java b/integration-tests/gradle/src/test/java/io/quarkus/gradle/AnnotationProcessorSimpleModuleTest.java index 7e109aa25ab0b..66a61bbc6b048 100644 --- a/integration-tests/gradle/src/test/java/io/quarkus/gradle/AnnotationProcessorSimpleModuleTest.java +++ b/integration-tests/gradle/src/test/java/io/quarkus/gradle/AnnotationProcessorSimpleModuleTest.java @@ -1,8 +1,9 @@ package io.quarkus.gradle; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import java.io.File; +import java.nio.file.Path; import org.junit.jupiter.api.Test; @@ -16,4 +17,17 @@ public void shouldRunTestCorrectly() throws Exception { assertThat(buildResult.getTasks().get(":test")).isEqualTo(BuildResult.SUCCESS_OUTCOME); } + + @Test + public void shouldContainsPanacheMarkerFile() throws Exception { + final File projectDir = getProjectDir("annotation-processor-simple-module"); + + BuildResult buildResult = runGradleWrapper(projectDir, "clean", "quarkusBuild"); + + assertThat(buildResult.getTasks().get(":quarkusBuild")).isEqualTo(BuildResult.SUCCESS_OUTCOME); + File buildDir = new File(projectDir, "build"); + + Path metaInfDir = buildDir.toPath().resolve("classes").resolve("java").resolve("main").resolve("META-INF"); + assertThat(metaInfDir.resolve("panache-archive.marker")).exists(); + } }