简体   繁体   English

Dagger2 + gradle + intellij:找不到生成的类并将其视为编译错误/不会自动完成

[英]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. 我正在尝试使用各种其他插件让intellij与我的功能性gradle build sans玩得很好。 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. 许多插件在测试目录等中与apt不兼容。

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. 启用注释处理器并将输出目录设置为/ build / classes / main和/ build / classes / test不会产生结果,尽管这是gradle插件似乎放置.java和.class文件所包含的dagger2编译。

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 我通过以下步骤解决了问题:1)修改compileJava任务以指定目标源位置

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

2)Tell IntelliJ Idea that those files are sources 2)告诉IntelliJ Idea这些文件是来源

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

PS Idea plugin shoud by applied: PS Idea插件应用:

apply plugin: 'idea'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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