简体   繁体   中英

Dagger2 + gradle + intellij: generated classes are not found and treated as a compile error/won't autocomplete

I'm trying to get intellij to play nice with my functional gradle build sans using various other plugins. The various plugins I've used break support with another plugin I'm required to use (it looks for generated sources in the default location among other issues). I've been working at this issue for a while and have had mild success, but always with caveats. Many of the plugins don't play nice with apt in the test directory, etc.

Enabling annotation processors and setting the output directories to /build/classes/main and /build/classes/test doesn't yield results, though this is where the gradle plugin seems to be placing the .java and .class files generated by including the dagger2-compiler.

I can get everything playing nice by creative tweaking of the generated source sets parameters in the module configurations, but this never sticks around. ie if you close the app you have to reconfigure the options.

Any help would be appreciated.

I solved the problem with the following steps: 1) Modify compileJava task to specify target sources location

compileJava {
    options.compilerArgs+= [
            "-s", project.projectDir.absolutePath + '/src/main/generated'
    ]
}

2)Tell IntelliJ Idea that those files are sources

idea {
    module {
        // generatedSourceDir does  not work for some reason
        sourceDirs  += file(project.projectDir.absolutePath + '/src/main/generated')
    }
}

PS Idea plugin shoud by applied:

apply plugin: 'idea'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM