Skip to content

Commit

Permalink
Enable the Panache annotation processor in Gradle if it's found on th…
Browse files Browse the repository at this point in the history
…e classpath

(cherry picked from commit f94ea77)
  • Loading branch information
aloubyansky authored and gsmet committed Dec 1, 2021
1 parent 6181097 commit 778d5d1
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,6 @@ public void execute(Task test) {
ConfigurationContainer configurations = project.getConfigurations();
JavaCompile compileJavaTask = (JavaCompile) tasks.getByName(JavaPlugin.COMPILE_JAVA_TASK_NAME);

// By default, gradle looks for annotation processors in the annotationProcessor configuration.
// This configure the compile task to look for annotation processors in the compileClasspath.
Configuration annotationProcessorConfig = configurations.create(ANNOTATION_PROCESSOR_CONFIGURATION_NAME)
.extendsFrom(
configurations.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME),
configurations.getByName(JavaPlugin.ANNOTATION_PROCESSOR_CONFIGURATION_NAME));
compileJavaTask.getOptions().setAnnotationProcessorPath(annotationProcessorConfig);

compileJavaTask.dependsOn(quarkusGenerateCode);

JavaCompile compileTestJavaTask = (JavaCompile) tasks.getByName(JavaPlugin.COMPILE_TEST_JAVA_TASK_NAME);
Expand Down Expand Up @@ -229,6 +221,15 @@ public void execute(Task test) {
new File(generatedTestSourceSet.getJava().getClassesDirectory().get().getAsFile(), provider));
}

// enable the Panache annotation processor on the classpath, if it's found among the dependencies
configurations.getByName(JavaPlugin.COMPILE_CLASSPATH_CONFIGURATION_NAME)
.getResolutionStrategy().eachDependency(d -> {
if ("quarkus-panache-common".equals(d.getTarget().getName())
&& "io.quarkus".equals(d.getTarget().getGroup())) {
project.getDependencies().add("annotationProcessor", d.getRequested().getGroup() + ":"
+ d.getRequested().getName() + ":" + d.getRequested().getVersion());
}
});
});

project.getPlugins().withId("org.jetbrains.kotlin.jvm", plugin -> {
Expand Down

0 comments on commit 778d5d1

Please sign in to comment.