A gradle plugin to run source code transformations using spoon on a project built with Gradle.
To use spoon-gradle-plugin, you need to add the plugin classes to the build script's classpath. To do this, you use a buildscript
block. The following example shows how you might do this when the JAR containing the plugin has been published to a local repository:
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath group: 'fr.inria.gforge.spoon',
name: 'spoon-gradle-plugin',
version:'1.3'
}
}
apply plugin: 'java'
apply plugin: 'spoon'
Consequently, when gradle build
is run on your project, the source code is first rewritten by spoon
before compilation.
Note: This project contains two plugins:
spoon
andspoon-android
. The first one is used to compile java source code and the pluginjava
is required. The second is used to compile android source code and the plugincom.android.application
orcom.android.library
are required.
Spoon can use processors to analyze and transform source code.
To add processors, one must:
- add a dependency in the
buildscript
block. - configure spoon.processors (you must specify the full qualified name).
In the example below, we add processor fr.inria.gforge.spoon.processors.CountStatementProcessor
and the dependency necessary to locate the processor.
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath group: 'fr.inria.gforge.spoon',
name: 'spoon-gradle-plugin',
version:'1.3'
classpath group: 'fr.inria.gforge.spoon',
name: 'spoon-processors',
version:'1.0-SNAPSHOT'
}
}
apply plugin: 'java'
apply plugin: 'spoon'
spoon {
processors = ['fr.inria.gforge.spoon.processors.CountStatementProcessor']
}
spoon-gradle-plugin analyzes and transforms the standard sourceSets as follows:
sourceSets {
main {
java {
srcDir 'src/main/project'
}
}
}
or for android projects:
android {
sourceSets {
main {
java {
srcDir 'src/main/project'
}
}
}
}
By default, spoon generate your source code and compile these sources but you can specify at the plugin that you want to compile your original sources with compileOriginalSources sets to true.
spoon {
compileOriginalSources true
}
To use the plugin, you first clone this repository and install it on your maven local repository.
Copyright Inria, all rights reserved.