Gilberto T.
Gilberto T.

Reputation: 378

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.

Upvotes: 2

Views: 1690

Answers (1)

Artem Yemelin
Artem Yemelin

Reputation: 66

Yes, by default Gradle puts all generated sources together with compiled ones. Please configure it like this:

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

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

And to add generated sources to the project

sourceSets {
    main {
        java {
            srcDir generatedJavaSourcesDir
        }
    }
}

Just add it to the build.gradle

Upvotes: 3

Related Questions