Skip to content

Commit b2d86dc

Browse files
committed
Move generating Java code based on protobuf into a separate project
Protobuf Gradle plugin expects that Gradle `java` plugin is present in the project, but KMP deprecated compatibility with `java` plugin. Soon this will become an error. To avoid, project error - generating Java code based on protobuf was moved into a separate Gradle subproject. 'kotlinx-serialization-protobuf' project Jvm test sources has now a normal dependency on this new subproject.
1 parent f9f160a commit b2d86dc

File tree

6 files changed

+43
-29
lines changed

6 files changed

+43
-29
lines changed

build.gradle.kts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,12 @@ gradle.taskGraph.whenReady {
166166

167167
// == projects lists and flags ==
168168
// getters are required because of variable lazy initialization in Gradle
169-
val unpublishedProjects get() = setOf("benchmark", "guide", "kotlinx-serialization-json-tests")
169+
val unpublishedProjects get() = setOf(
170+
"benchmark",
171+
"guide",
172+
"kotlinx-serialization-json-tests",
173+
"proto-test-model",
174+
)
170175
val excludedFromBomProjects get() = unpublishedProjects + "kotlinx-serialization-bom"
171176
val globalCompilerArgs
172177
get() = listOf(

formats/protobuf/build.gradle.kts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,16 @@
22
* Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44
import Java9Modularity.configureJava9ModuleInfo
5-
import com.google.protobuf.gradle.*
6-
import org.gradle.kotlin.dsl.protobuf
75

86
plugins {
9-
java // Needed for protobuf plugin only
107
kotlin("multiplatform")
118

129
alias(libs.plugins.serialization)
13-
alias(libs.plugins.protobuf)
1410

1511
id("native-targets-conventions")
1612
id("source-sets-conventions")
1713
}
1814

19-
protobuf {
20-
protobuf.protoc {
21-
// Download from repositories
22-
artifact = libs.protoc.get().toString()
23-
}
24-
}
25-
26-
tasks.clean {
27-
delete(protobuf.protobuf.generatedFilesBaseDir)
28-
}
29-
3015
kotlin {
3116
sourceSets {
3217
configureEach {
@@ -40,24 +25,12 @@ kotlin {
4025
}
4126

4227
jvmTest {
43-
kotlin.srcDirs(file("${protobuf.protobuf.generatedFilesBaseDir}/test/java"))
44-
4528
dependencies {
46-
implementation(libs.protobuf.java)
29+
implementation(project(":kotlinx-serialization-protobuf:proto-test-model"))
4730
implementation(libs.kotlintest)
4831
}
4932
}
5033
}
5134
}
5235

53-
sourceSets.test {
54-
extensions.configure<SourceDirectorySet>("proto") {
55-
srcDirs("testProto", "jvmTest/resources/common")
56-
}
57-
}
58-
59-
tasks.compileTestKotlinJvm {
60-
dependsOn("generateTestProto")
61-
}
62-
6336
configureJava9ModuleInfo()
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2017-2025 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
import com.google.protobuf.gradle.*
6+
import org.gradle.kotlin.dsl.protobuf
7+
8+
plugins {
9+
`java-library`
10+
alias(libs.plugins.protobuf)
11+
}
12+
13+
protobuf {
14+
protobuf.protoc {
15+
// Download from repositories
16+
artifact = libs.protoc.get().toString()
17+
}
18+
}
19+
20+
java.toolchain.languageVersion.set(JavaLanguageVersion.of(jdkToolchainVersion))
21+
22+
tasks.clean {
23+
delete(protobuf.protobuf.generatedFilesBaseDir)
24+
}
25+
26+
sourceSets.main {
27+
extensions.configure<SourceDirectorySet>("proto") {
28+
srcDirs("testProto", "../jvmTest/resources/common")
29+
}
30+
}
31+
32+
dependencies {
33+
api(libs.protobuf.java)
34+
}

settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ project(":kotlinx-serialization-json-tests").projectDir = file("./formats/json-t
6363

6464
include(":kotlinx-serialization-protobuf")
6565
project(":kotlinx-serialization-protobuf").projectDir = file("./formats/protobuf")
66+
include(":kotlinx-serialization-protobuf:proto-test-model")
67+
project(":kotlinx-serialization-protobuf:proto-test-model").projectDir = file("./formats/protobuf/proto-test-model")
6668

6769
include(":kotlinx-serialization-cbor")
6870
project(":kotlinx-serialization-cbor").projectDir = file("./formats/cbor")

0 commit comments

Comments
 (0)