Skip to content

Commit

Permalink
Fix panache annotation processor registration
Browse files Browse the repository at this point in the history
  • Loading branch information
glefloch committed Oct 29, 2021
1 parent 36b7827 commit 806bf2d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ExtensionDependency> devModeExtensions = conditionalDependenciesEnabler
Expand All @@ -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<ResolvedArtifact> 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<Path> getSourcesParents(SourceSet mainSourceSet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@ test {
}

repositories {
mavenCentral()
if (System.properties.containsKey('maven.repo.local')) {
maven {
url System.properties.get('maven.repo.local')
}
} else {
mavenLocal()
}
mavenCentral()
}

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}"

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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();
}
}

0 comments on commit 806bf2d

Please sign in to comment.