I am trying to build a GIT repository to store common protocol buffers. What I am trying to do is minimizing the common boilerplate code across different projects.
I am thinking something like the following structure. Hence, when an application include my source as a "git submodule", it can include only "necessary proto + Language".
rootProject
|-- proto-1
| |--src
| | |-- main
| | |-- proto
| | |-- proto-a.proto
| | `-- proto-a.proto
| |-- Java
| | |-- build.gradle.kts
| |-- Kotlin
| | |-- build.gradle.kts
| |-- JavaScript
| |-- build.gradle.kts
|-- proto-2
| |--src
| | |-- main
| | |-- proto
| | |-- proto-c.proto
| | `-- proto-d.proto
| |-- Java
| | |-- build.gradle.kts
| |-- Python
| | |-- build.gradle.kts
|---- settings.gradle
`---- build.gradle.kts
The above code works well, if I define protobuf and sourceSets for each build.gradle.kts, like
protobuf {
generateProtoTasks {
all().forEach {
it.builtins {
id("kotlin")
}
}
}
}
sourceSets {
main {
proto {
srcDir("../src/main/proto")
}
}
}
However, as you may see, the above code is duplicate across build.gradle.kts. If I can set up the above code in the rootpage build.gradle.kts, I think it will be very easy to use it.
This is my current build.gradle.kts for the root project. (Surely, this is incomplete)
allprojects {
apply(plugin = "java")
apply(plugin = "com.google.protobuf")
repositories {
maven {
setUrl("https://nexus.yanolja.in/repository/maven-public/")
}
}
protobuf {
protoc { artifact = "com.google.protobuf:protoc:3.22.0" }
}
}
subprojects {
apply(plugin = "java")
val implementation by configurations
dependencies {
implementation("com.google.protobuf:protobuf-java:3.22.0")
}
}
val mainSource = project.the<SourceSetContainer>().findByName(SourceSet.MAIN_SOURCE_SET_NAME)
mainSource?.allSource?.srcDir("../src/main/proto")