Skip to content

Commit

Permalink
Remove support for the Kotlin JS plugin (#271)
Browse files Browse the repository at this point in the history
Reworks Kotlin JS and multiplatform support to run the protoc plugin one time per target, placing generated code in a separate directory per target.

Fixes #208.
  • Loading branch information
andrewparmet authored Dec 16, 2024
1 parent c7c0676 commit 484dca0
Show file tree
Hide file tree
Showing 45 changed files with 2,514 additions and 316 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
kotlin: [ 1.8.22, 1.9.24 ]
kotlin: [ 1.8.22, 1.9.25, 2.0.21, 2.1.0 ]
jdk: [ 11, 17, 21 ]

runs-on: ${{ matrix.os }}
Expand Down
4 changes: 1 addition & 3 deletions buildSrc/src/main/kotlin/LocalProtoktBuild.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ import protokt.v1.gradle.configureProtokt
import java.io.File

fun Project.localProtokt(disableJava: Boolean = true) {
configureProtokt(this, null, disableJava) {
"$rootDir/protokt-codegen/build/install/$CODEGEN_NAME/bin/$CODEGEN_NAME"
}
configureProtokt(this, null, disableJava, "$rootDir/protokt-codegen/build/install/$CODEGEN_NAME/bin/$CODEGEN_NAME")

afterEvaluate {
tasks.withType<GenerateProtoTask> {
Expand Down
9 changes: 3 additions & 6 deletions buildSrc/src/main/kotlin/RemotePublishing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import com.google.protobuf.gradle.GenerateProtoTask
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinJs
import com.vanniktech.maven.publish.KotlinJvm
import com.vanniktech.maven.publish.KotlinMultiplatform
import com.vanniktech.maven.publish.MavenPublishBaseExtension
Expand All @@ -31,6 +30,7 @@ import org.gradle.kotlin.dsl.the
import org.gradle.kotlin.dsl.withType
import org.gradle.plugins.signing.Sign
import org.gradle.plugins.signing.SigningExtension
import protokt.v1.gradle.KotlinPlugins

private object Pgp {
val key by lazy {
Expand Down Expand Up @@ -85,15 +85,12 @@ fun Project.enablePublishing(defaultJars: Boolean = true) {
}

if (defaultJars) {
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
pluginManager.withPlugin(KotlinPlugins.MULTIPLATFORM) {
configure(KotlinMultiplatform(JavadocJar.Empty()))
}
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
pluginManager.withPlugin(KotlinPlugins.JVM) {
configure(KotlinJvm(JavadocJar.Empty(), true))
}
pluginManager.withPlugin("org.jetbrains.kotlin.js") {
configure(KotlinJs(JavadocJar.Empty()))
}
}

afterEvaluate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
plugins {
id("protokt.common-conventions")
id("com.android.library")
kotlin("android")
`kotlin-android`
}

javaBasedProjectConventions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

plugins {
id("protokt.jvm-conventions")
kotlin("kapt")
`kotlin-kapt`
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinVersion

plugins {
id("protokt.common-conventions")
kotlin("jvm")
kotlin
}

javaBasedProjectConventions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

plugins {
kotlin("multiplatform")
`kotlin-multiplatform`
id("protokt.common-conventions")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2024 Toast, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
id("protokt.multiplatform-conventions")
}

enablePublishing()
trackKotlinApiCompatibility()
36 changes: 18 additions & 18 deletions examples/grpc-node/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
* limitations under the License.
*/

import com.google.protobuf.gradle.proto
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsExec
import protokt.v1.gradle.protokt

plugins {
id("org.jetbrains.kotlin.js")
`kotlin-multiplatform`
}

kotlin {
Expand All @@ -31,6 +30,23 @@ kotlin {
binaries.executable()
useCommonJs()
}

sourceSets {
val jsMain by getting {
dependencies {
api(project(":protokt-runtime-grpc-lite"))
api(project(":examples:protos"))
api(libs.kotlinx.coroutines.core)
}
}

val jsTest by getting {
dependencies {
api(kotlin("test"))
api(libs.kotlinx.coroutines.test)
}
}
}
}

localProtokt()
Expand All @@ -44,22 +60,6 @@ protokt {
}
}

dependencies {
implementation(project(":examples:protos"))
implementation(libs.kotlinx.coroutines.core)

testImplementation(kotlin("test"))
testImplementation(libs.kotlinx.coroutines.test)
}

sourceSets {
named("jsMain") {
proto {
srcDir("../protos/src/main/proto")
}
}
}

tasks.withType<NodeJsExec> {
args(listOfNotNull(properties["service"], properties["mode"], properties["args"]))
}
Expand Down
4 changes: 1 addition & 3 deletions extensions/protokt-extensions-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
*/

plugins {
id("protokt.multiplatform-conventions")
id("protokt.multiplatform-published-conventions")
}

enablePublishing()
compatibleWithAndroid()
trackKotlinApiCompatibility()
6 changes: 1 addition & 5 deletions extensions/protokt-extensions-lite/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ import protokt.v1.gradle.protokt
import protokt.v1.gradle.protoktExtensions

plugins {
id("protokt.multiplatform-conventions")
id("protokt.multiplatform-published-conventions")
}

localProtokt()
enablePublishing()
trackKotlinApiCompatibility()

spotless {
kotlin {
Expand All @@ -42,8 +40,6 @@ protokt {

kotlin {
sourceSets {
val commonMain by getting {}

val jvmMain by getting {
dependencies {
api(project(":protokt-core-lite"))
Expand Down
5 changes: 1 addition & 4 deletions extensions/protokt-extensions-simple/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@
*/

plugins {
id("protokt.multiplatform-conventions")
id("protokt.multiplatform-published-conventions")
}

enablePublishing()
trackKotlinApiCompatibility()

kotlin {
sourceSets {
val jvmMain by getting {
Expand Down
4 changes: 1 addition & 3 deletions extensions/protokt-extensions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ import com.google.protobuf.gradle.proto
import protokt.v1.gradle.protokt

plugins {
id("protokt.multiplatform-conventions")
id("protokt.multiplatform-published-conventions")
}

localProtokt()
enablePublishing()
compatibleWithAndroid()
trackKotlinApiCompatibility()

spotless {
kotlin {
Expand Down
Loading

0 comments on commit 484dca0

Please sign in to comment.