we have a gradle plugin that generates protos for ...
# gradle
j
we have a gradle plugin that generates protos for both kotlin and java and i'm hitting an interesting bug where kotlin projects consume java protos. the compileKotlin task isn't able to find the java generated sources.
Copy code
val compileKotlinTask = project.tasks.named("compileKotlin") as TaskProvider<KotlinCompile>
        compileKotlinTask.configure {
          it.source(javaOutDirs)  // javaOutDirs is where the java protos are generated
          it.dependsOn(wireTask)
        }
but my gradle output shows:
Copy code
14:56:58.695 [DEBUG] [org.gradle.api.Task] [KOTLIN] all kotlin sources: src/main/java/com/squareup/dinosaurs/Sample.kt
14:56:58.695 [DEBUG] [org.gradle.api.Task] [KOTLIN] compileKotlin source roots: [
	/...src/test/projects/kotlin-project-java-protos/src/main/java/com/squareup/dinosaurs/Sample.kt]
14:56:58.695 [DEBUG] [org.gradle.api.Task] [KOTLIN] compileKotlin java source roots: [
// why empty?!
	]
t
Hm, doesn't
setSource()
should set only kotlin sources?
interestingly that
setSource()
overloads has different behaviour:
Copy code
// override setSource to track source directory sets and files (for generated android folders)
    override fun setSource(sources: Any?) {
        sourceRootsContainer.set(sources)
        super.setSource(sources)
    }

    // override source to track source directory sets and files (for generated android folders)
    override fun source(vararg sources: Any?): SourceTask? {
        sourceRootsContainer.add(*sources)
        return super.source(*sources)
    }
where
sourceRootsContainer.set(sources)
clears already existing roots
though such behaviour aligns with
SourceTask
j
correct, but i'm calling
source()
instead of
setSource()
, so it should append to the list, right?
or if that's meant for kotlin sources only, is there a way to pass java sources? or will i have to invoke another javac pass for the protos themselves (not ideal...)?
t
yeah, you are right - it should append
or if that's meant for kotlin sources only, is there a way to pass java sources? or will i have to invoke another javac pass for the protos themselves (not ideal...)?
I would expect that this class only takes Kotlin sources via
PatternFilterable
interface
not the best way, but I can think of generating jar out of java classes and adding it as classpath to
KotlinCompile
tasks
also check if wire task runs actualy before Kotlin compile by running:
Copy code
./gradlew -m generateProtos
j
yup, confirmed that before:
Copy code
:generateProtos SKIPPED
:compileKotlin SKIPPED
:compileJava SKIPPED
ooh that thread is interesting, let me take a look
so i was able to reverse the order, but i'm still getting the same error 🤔
ok, found the issue after a bit more digging: https://youtrack.jetbrains.com/issue/KT-12715
t
I think, in general, usage of
afterEvaluate { .. }
is deprecated
as it leads to such kind of problems
j
right, i'm trying to figure out a way around this. ideally, the kotlin plugin authors would move to using lazy eval and/or a live collection
funny enough, i think i came across a github issue showing similar behavior with your handle on it 🙂