Search code examples
javaannotationsannotation-processinginria-spoon

Using Spoon Gradle Plugin for create customized Annotations Processor


I'm trying to write annotation processor in android using SPOON.

So my question is when I have written my annotation processor class, how to indicate it to the compiler.

Suppose that my class is located at com.craftman.spoonprocessor.CustomProcessor


Solution

  • if I understand well you're trying to specify Spoon to use your processor with Gradle plugin. The easiest way, is to follow the explanations given there: https://github.com/SpoonLabs/spoon-gradle-plugin#how-to-add-processors. In short, you create a specific gradle module containing only the code of your processor, then you can use almost the same Gradle file you show for the project you want to process, you just need to add a dependency towards your new processor module:

    buildscript {
        repositories {
            jcenter()
            mavenLocal()
            maven {
                url 'http://spoon.gforge.inria.fr/repositories/'
            }
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.3.0'
            classpath group: 'fr.inria.gforge.spoon',
                    name: 'spoon-gradle-plugin',
                    version:'1.0-SNAPSHOT'
            // here you put your module dependency
            classpath group: 'com.craftman.spoonprocessor',
                    name: 'customprocessor',
                    version: '1.0_SNAPSHOT'
            classpath files('build/classes/main')
    
    
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            jcenter()
        }
    }
    
    apply plugin: 'java'
    apply plugin: 'spoon'
    
    spoon {
        processors = ['com.craftman.spoonprocessor.CustomProcessor']
    }
    

    Hope this helps!