I have a gradle project and I want to use dagger 2.0 in it. I don\'t know how to configure IntelliJ and gradle to generate files and let IntelliJ find them?
My build
I had problems with the existings plugins, so I added the following to my build.gradle:
def daggerVersion = "2.4"
// APT >>
def genPath = new File(buildDir,"generated/java/APT" )
task createGenPath << {
if(!genPath.exists()){
genPath.mkdirs()
}
}
compileJava.dependsOn(createGenPath)
compileJava {
options.compilerArgs << '-s' << genPath
}
// APT <<
dependencies {
compile "com.google.dagger:dagger:$daggerVersion"
compile "com.google.dagger:dagger-compiler:$daggerVersion"
}
// APT IDEA >>
idea.module {
sourceDirs += genPath
// maybe add to generatedSourceDirs
iml {
withXml {
File ideaCompilerXml = project.file('.idea/compiler.xml')
if (ideaCompilerXml.isFile()) {
Node parsedProjectXml = (new XmlParser()).parse(ideaCompilerXml)
updateIdeaCompilerConfiguration(parsedProjectXml)
ideaCompilerXml.withWriter { writer ->
XmlNodePrinter nodePrinter = new XmlNodePrinter(new PrintWriter(writer))
nodePrinter.setPreserveWhitespace(true)
nodePrinter.print(parsedProjectXml)
}
}
}
}
}
static void updateIdeaCompilerConfiguration( Node projectConfiguration) { //actually resets APT
Object compilerConfiguration = projectConfiguration.component.find { it.@name == 'CompilerConfiguration' }
compilerConfiguration.annotationProcessing.replaceNode{
annotationProcessing() {
profile(default: 'true', name: 'Default', enabled: 'true') {
sourceOutputDir(name: '')
sourceTestOutputDir(name: '')
outputRelativeToContentRoot(value: 'true')
processorPath(useClasspath: 'true')
}
}
}
}
// APT IDEA <<