Generate code in a module based on annotations from another module

Viewed 85

I am trying to make an annotation processor that processes some annotations named GenerateRepository and runs that processor in a module called server. That server module depends on a common module, which is where the classes are annotated with this GenerateRepository annotation. My question is, is there any way to make the processor run on that come from a dependency? I am using Gradle to manage dependencies and IntelliJ.

What I have until now is something on the lines of:

processor module, where the annotation and the processor classes are defined. The processor tries to write the generated class file in a package called "repo", which is in the server module

common module, where a domain class such as the one below is defined

@GenerateRepository
public class A{
...
}

server module, where I want the processor to run and have the generated files get into the "repo" package

The gradle builds look as such:

  • server gradle:
dependencies {
    compile project(':common')
    annotationProcessor project(':processor')
}
  • common gradle:
dependencies {
    compile project(":processor")
}
  • processor Gradle is empty

  • the project wide gradle file looks as such:

allprojects {
    apply plugin: 'java'
    apply plugin: 'idea'

    group 'org.chair-fight'
    version '1.0-SNAPSHOT'

    sourceCompatibility = JavaVersion.VERSION_15

    idea.module.scopes.PROVIDED.plus += [configurations.annotationProcessor]
}

The problem is mainly that when I build the project the processor doesn't look in the dependencies of the server module, only in the server module. What I want is to have it run also on classes that are in the dependencies

0 Answers
Related