Project 1 (annotation project):
build.gradle
plugins {
id 'java'
}
apply plugin: 'java'
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
annotationProcessor 'com.google.auto.service:auto-service:1.0.1'
implementation 'com.google.auto.service:auto-service:1.0.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}
test {
useJUnitPlatform()
}
Annotation
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Table {
String value();
String[] ignoreColumns() default {};
}
Processor
@AutoService(TableProcessor.class)
@SupportedAnnotationTypes("com.github.ahuangJM.annotations.Table")
@SupportedSourceVersion(SourceVersion.RELEASE_8)
public class TableProcessor extends AbstractProcessor {
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
System.out.println("init hit!");
super.init(processingEnv);
}
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
final Messager messager = processingEnv.getMessager();
messager.printMessage(Diagnostic.Kind.NOTE, "Processing...");
return true;
}
}
\resources\META-INF\javax.annotation.processing.Processor
org.example.processors.TableProcessor
Project 2 (annotation project consumer):
Annotation Consumer
@Table("user-info")
public class UserInfo {
}
build.gradle
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
implementation files("REDACTED\\code-generator-annotation.jar")
annotationProcessor files("REDACTED\\code-generator-annotation.jar")
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
}
test {
useJUnitPlatform()
}
This should be a very simple annotation processor just printing debugging statements.
This all seems correct to me, but process() is not running when I build/run project 2. I have tried overriding getSupportedVersion() and getSupportedAnnotationTypes() as well. That didn't do anything. Also tried without @AutoService, that didn't change anything as well.
EDIT: why am i can getting the print() and/or printMessage() statement?