https://kotlinlang.org logo
Title
d

Dariusz Kuc

05/11/2020, 3:28 PM
hello! I’m trying to split up our protobuf module to produce two separate artifacts - Java+Reactor and Kotlin specific (currently it builds single artifact with optional dependencies for both). My project setup
- build.gradle.kts // [1] root builds java artifact
- src
  - main/java - some common utils here
  - main/resources - some common resources
  - main/proto
- kotlin-specific
  - build.gradle.kts [2] builds kotlin artfiact with some sources from [1]
  - src/main/kotlin - kotlin specific utils
Whats the proper way to reference sources/resources from root [1] in my kotlin specific build [2]? e.g. I could do something like
sourceSets {
    main {
        java.srcDir("${rootProject.java}/src/main/java")
    }
}
but wondering if there is a better way
a

araqnid

05/11/2020, 3:34 PM
Surely you just want to declare your root project as an api dependency of the kotlin-specific project?
dependencies {
  api(project(":"))
}
Then it will be published as a compile-time dependency rather than duplicating the classes
d

Dariusz Kuc

05/11/2020, 4:14 PM
actually I don’t
my root project will contain some auto generated code that is Java specific and brings in some dependencies that I don’t care about (ie. reactor)
library most just generates protos • root -> plain Java + reactor support • kotlin -> kotlin specific (currently requires plain Java), i.e. coroutine support + DSL builders
a

araqnid

05/11/2020, 4:33 PM
I’d split it into common, java/reactor and kotlin/coroutine artifacts
d

Dariusz Kuc

05/11/2020, 4:38 PM
unsure if there is going to be anything in common, all the
grpc
plugin examples use
protobuf
setup that always rely on
java
lib and then adds separate generators (i.e. unsure if i can pull the generated base java sources to a common artifact, guess can try)
same file cannot be part of multiple modules
*at least in IDEA
so this is troublesome as I need to share protos between java + kotlin project
a

araqnid

05/11/2020, 6:08 PM
if you’re generating the source files in Gradle anyway, you could have two protobuf tasks- one generates them with the grpc plugin (in your Java project) and one without (in your Kotlin project)
then there would be two distinct sets of sources to avoid confusing idea
d

Dariusz Kuc

05/11/2020, 6:12 PM
generated sources would be different but resources (proto files) are shared and this confuses idea