marcoferrer / kroto-plus

gRPC Kotlin Coroutines, Protobuf DSL, Scripting for Protoc
Apache License 2.0
493 stars 28 forks source link

sourceSet other than `main` won't output #64

Open RdeWilde opened 5 years ago

RdeWilde commented 5 years ago

When I run gradle, it generates output files for the proto-files. These are put into $projectDir/src/$sourceSet/java/my/org/models/a.kt (or a.java). This works for the sourceSet main, but not for other sourceSets like commonMain, although I defined the task for all sourceSets. The protofiles and directories are identical between sourceSet main and commonMain (I created main just for testing).

Partial gradle build file here (https://gist.github.com/RdeWilde/ec3a5c9432004579643a47ed5fee3397)

Directory structure is:

src
+ commonMain
|    |
|    + java     // no output  :-(
|    + proto
|         |
|         + protofile1.proto
|         + protofile2.proto
|
+ main
     |
     + java    // does have output  :-)
     + proto
          |
          + protofile1.proto
          + protofile2.proto
marcoferrer commented 5 years ago

I’ve ran into this issue before but haven’t had time to get it resolved. The last time I dug into it there were two things that need to be resolved. The first being that the source sets in the kotlin multi platform Gradle plugin we’re not being instantiated using an object factory. This means that their instance at runtime was not ExtensionAware. The reason this matter is because of compatibility with the existing protobuf Gradle plugin. It needs the source sets it’s applied on to be extension aware.

The other issue is that the protobuf Gradle plugin needs to be updated to support this new source set type and take the kotlin multiple plugin into consideration during bootstrapping.

One work around I used was to generate the sources in a separate module and copy them over to commonMain for dev/testing.

RdeWilde commented 5 years ago

Yes, I manually copy the files from main to commonMain now.

Sounds like it will be a little too hard for me to fix. Maybe I'll give it a try. Thanks for the info :+1:

RdeWilde commented 5 years ago

This line should implement an object factory? https://github.com/JetBrains/kotlin/blob/988df517dd5c0159315b3d1da94712bdd635e681/libraries/tools/kotlin-gradle-plugin/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/sources/KotlinSourceSetFactory.kt#L26

And this inteface should implement ExtensionAware? https://github.com/JetBrains/kotlin/blob/deb416484c5128a6f4bc76c39a3d9878b38cec8c/libraries/tools/kotlin-gradle-plugin-api/src/main/kotlin/org/jetbrains/kotlin/gradle/plugin/KotlinSourceSet.kt#L12

and take the kotlin multiple plugin into consideration during bootstrapping.

Not sure what this means

marcoferrer commented 5 years ago

Sorry that was a typo. I meant to say that the protobuf plugin would have to be made aware of the kotlin multiplatform plugin. I dont think the source set would need to explicitly implement ExtensionAware. Once its created by the object factory, the proxy that wraps the class will implicitly add it.

marcoferrer commented 4 years ago

I took some time to track down the issue I filed related to this. Linking it here for visibility KT-29156

I dont see this getting resolved anytime soon but its worth centralizing the history here at the very least.