0

I have two gradle projects (A, B) And they use the same annotation processor the problem is that A has exactly one part of the processor it does not need.

Is there a way to configure gradle so that the annotation processor performs differently for A vs B?

I would not like to make two annotation processors since they are identical except for one tiny part. (think like 2-3 lines of code)

dtracers
  • 1,534
  • 3
  • 17
  • 37

1 Answers1

0

I can't tell about gradle, but in maven you can pass compile time arguments in the following way

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.5.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
                <encoding>UTF-8</encoding>
                <generatedSourcesDirectory>${project.build.directory}/generated-sources/</generatedSourcesDirectory>
                <annotationProcessors>
                    <annotationProcessor>org.rapster.xxx.xxx.xxComponentProcessor</annotationProcessor>
                </annotationProcessors>
                <compilerArgs>
                   <arg>-Awidget=something</arg>
                </compilerArgs>
            </configuration>
        </plugin>
    </plugins>
</build>

This compile time argument can be read in your annotation processor by the following snippet in init function of processor

this.widget = processingEnv.getOptions().get("widget");

You can use this property to do certain conditional action.

Same can be done via gradle, I believe

vishva
  • 366
  • 5
  • 17