I'm trying to get gradle to work with some generat...
# community-support
r
I'm trying to get gradle to work with some generated code, but during
compileJava
it does not find the corresponding code, I get the following:
Copy code
/home/rohdef/git/protobuf/producer/src/main/java/dk/rohdef/protobuf/Foo.java:5: error: package GreeterGrpc does not exist
public final class Foo extends GreeterGrpc.GreeterImplBase
I can confirm that the generated class does exist as expected in
build/generated/source/proto/main/java
and
build/generated/source/proto/main/grpc
I have added in `build.gradle.kts`:
Copy code
sourceSets {
    main {
        java {
            project.logger.error("${protobuf.generatedFilesBaseDir}/main/grpc")
            project.logger.error("${protobuf.generatedFilesBaseDir}/main/java")
            srcDirs(
                "${protobuf.generatedFilesBaseDir}/main/grpc",
                "${protobuf.generatedFilesBaseDir}/main/java",
            )
        }
    }
}
and through the logs confirmed that the paths are indeed correct and the files in the added source directories are indeed
.java
files so I'm at a bit of a loss here, it seems to me that the underlying javac is getting run with a wrong/bad setup. How do I best debug this? How do I get gradle to actually include my source sets and not only expose them to IntelliJ?
v
That's hard to guess, can you show an MCVE? Besides that, you should never configure explicit paths like that, as you then for example miss the task dependency. And adding the task dependency manually using
dependsOn
is very bad practice and only partly working. Assuming the task that generates those files properly declares is outputs, just use the task itself as
srcDir
, then the outputs become source files and any consumer of source files automatically has the necessary task dependency.