Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Wasm Publication #208

Merged
merged 1 commit into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import org.jetbrains.kotlin.gradle.targets.js.dsl.KotlinJsTargetDsl
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
import java.io.File

fun ProjectKotlinConfig.configureJsAndWasmJs() {
fun ProjectKotlinConfig.configureJs() {
if (!js) {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,26 @@ package util
import org.gradle.api.Project
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.api.provider.Property
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.kotlin.dsl.maven
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import java.io.File

const val KOTLINX_RPC_PREFIX = "kotlinx-rpc"

/**
* Important to configure inside [KotlinTarget.mavenPublication]
* AND in [PublishingExtension.configurePublication] in the conventions-publishing.gradle.kts file.
*/
@Suppress("KDocUnresolvedReference")
fun MavenPublication.setPublicArtifactId(project: Project) {
val publication = this

publication.artifactId = "$KOTLINX_RPC_PREFIX-$artifactId"
project.logger.info("Altered artifactId for $name publication: $artifactId")
if (!publication.artifactId.startsWith(KOTLINX_RPC_PREFIX)) {
publication.artifactId = "$KOTLINX_RPC_PREFIX-$artifactId"
project.logger.info("Altered artifactId for $name publication: $artifactId")
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ private fun Project.configureDetekt(targets: List<KotlinTarget>) {
}

fun ProjectKotlinConfig.configureKotlin(action: Action<KotlinMultiplatformExtension> = Action { }) {
configureJsAndWasmJs()

kotlin {
val includedTargets = configureTargets(this@configureKotlin)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fun NamedDomainObjectContainer<KotlinSourceSet>.applyCompilerSpecificSourceSets(
// choose 'latest' if there are no more specific ones
val mostSpecificApplicable = vsSets.mostSpecificVersionOrLatest(kotlinVersion)

logger.info(
logger.lifecycle(
"${project.name}: included version specific source sets: " +
"${core.name}${mostSpecificApplicable?.let { ", $name" } ?: ""}"
)
Expand All @@ -49,7 +49,9 @@ fun NamedDomainObjectContainer<KotlinSourceSet>.applyCompilerSpecificSourceSets(
set.configureResources(sourceSetPath)

val excluded = vsSets.filter { it != mostSpecificApplicable }
logger.info("${project.name}: excluded version specific source sets: [${excluded.joinToString { it.name }}]")
logger.lifecycle(
"${project.name}: excluded version specific source sets: [${excluded.joinToString { it.name }}]"
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ configure<KotlinMultiplatformExtension> {

withKotlinConfig {
configureKotlin()
configureJs()
configureWasm()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fun PublishingExtension.configurePublication() {
publication.artifact(javadocJar)
}

// mainly for kotlinMultiplatform publication
publication.setPublicArtifactId(project)

if (!isGradlePlugin) {
Expand Down
11 changes: 9 additions & 2 deletions gradle-conventions/src/main/latest/util/wasm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
package util

import org.gradle.kotlin.dsl.invoke
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

@OptIn(ExperimentalWasmDsl::class)
fun ProjectKotlinConfig.configureWasm() {
fun KotlinTarget.configurePublication() {
mavenPublication {
setPublicArtifactId(project)
}
}

kotlin {
if (wasmJs) {
wasmJs {
Expand All @@ -19,7 +26,7 @@ fun ProjectKotlinConfig.configureWasm() {
d8()

binaries.library()
}
}.configurePublication()

sourceSets {
wasmJsMain {
Expand All @@ -39,7 +46,7 @@ fun ProjectKotlinConfig.configureWasm() {
nodejs()

binaries.library()
}
}.configurePublication()
}
}
}
2 changes: 1 addition & 1 deletion tests/compiler-plugin-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,6 @@ fun Test.setJarPathAsProperty(
}

fun Test.systemPropertyLogged(name: String, value: Any) {
logger.info("Setting prop $name=$value")
logger.lifecycle("Setting test prop $name=$value")
systemProperty(name, value)
}