首页 > 解决方案 > IntelliJ IDEA annotation processing doesn't generate sources in configured forlder

问题描述

I'm struggling with IntelliJ Idea (IntelliJ IDEA 2018.3.2 (Ultimate Edition)), Gradle, and Immutables library. What I'm trying to do is generating sources in the generated directory as expected by the configuration at Using annotation processor in IDE > IntelliJ IDEA.

At the moment the result I get is that both compiled classes and sources are put inside /build/classes/java/main Have you got the same issues? Do you have suggestions to solve the problem? I'm looking for answers but I didn't find a working solution yet.

标签: javagradleintellij-ideaannotation-processor

解决方案


是的,默认情况下,Gradle 将所有生成的源代码与编译的源代码放在一起。请像这样配置它:

def generatedJavaSourcesPath = "$buildDir/generated-sources/java"
def generatedJavaSourcesDir = file(generatedJavaSourcesPath)

compileJava {
    options.compilerArgs = [
            // Override the directory where to place generated source files.
            "-s",
            generatedJavaSourcesPath 
    ]
}

并将生成的源添加到项目中

sourceSets {
    main {
        java {
            srcDir generatedJavaSourcesDir
        }
    }
}

只需将其添加到build.gradle


推荐阅读