Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. i.e. if you close the app you have to reconfigure the options.

Any help would be appreciated.

like image 598
accordionfolder Avatar asked Dec 02 '25 15:12

accordionfolder


1 Answers

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')
    }
}

P.S Idea plugin shoud by applied:

apply plugin: 'idea'
like image 70
Василий Кудрявцев Avatar answered Dec 04 '25 04:12

Василий Кудрявцев



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!