
com.neenbedankt.gradle.androidapt.AndroidAptPlugin.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of android-apt Show documentation
Show all versions of android-apt Show documentation
A Gradle plugin that ensures Android Studio will pick up generated source from annotation processors and provides an apt configuration for excluding annotation processors from runtime dependencies.
package com.neenbedankt.gradle.androidapt
import org.gradle.api.Project
import org.gradle.api.Plugin
import org.gradle.api.ProjectConfigurationException
class AndroidAptPlugin implements Plugin {
void apply(Project project) {
//TODO does it make sense to apply this to a library project?
if(!project.plugins.findPlugin("android")) {
throw new ProjectConfigurationException("Android plugin must be applied to the project")
}
project.configurations.create('apt').extendsFrom(project.configurations.compile)
project.afterEvaluate {
project.android.applicationVariants.all { variant ->
def aptOutputDir = project.file(new File(project.buildDir, "source/apt"))
def aptOutput = new File(aptOutputDir, variant.dirName)
def sourceSet = new File(variant.dirName).getName()
project.android.sourceSets[sourceSet].java.srcDirs+= aptOutput.getPath()
variant.javaCompile.options.compilerArgs += [
'-processorpath', project.configurations.apt.getAsPath(),
'-s', aptOutput
]
variant.javaCompile.source = variant.javaCompile.source.filter { p ->
return !p.getPath().startsWith(aptOutputDir.getPath())
}
variant.javaCompile.doFirst {
aptOutput.mkdirs()
}
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy