Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.SpoonLabs:spoon-gradle-plugin:1.4'
}
dependencies {
implementation("com.github.SpoonLabs:spoon-gradle-plugin:1.4")
}
<dependency>
<groupId>com.github.SpoonLabs</groupId>
<artifactId>spoon-gradle-plugin</artifactId>
<version>1.4</version>
</dependency>
libraryDependencies += "com.github.SpoonLabs" % "spoon-gradle-plugin" % "1.4"
:dependencies [[com.github.SpoonLabs/spoon-gradle-plugin "1.4"]]
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:
spoonandspoon-android. The first one is used to compile java source code and the pluginjavais required. The second is used to compile android source code and the plugincom.android.applicationorcom.android.libraryare required.
Spoon can use processors to analyze and transform source code.
To add processors, one must:
buildscript block.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.