From 418a72b48213aec7b654ae4f49c612e7d4c2573e Mon Sep 17 00:00:00 2001 From: Aleksey Mikhailov Date: Sun, 7 Aug 2022 21:34:32 +0700 Subject: [PATCH] new hosts and jvm plugins --- build.gradle.kts | 10 ++++ gradle/libs.versions.toml | 2 +- .../moko/gradle/HostsPublicationPlugin.kt | 37 +++++++++++++++ .../dev/icerock/moko/gradle/JvmPlugin.kt | 46 +++++++++++++++++++ 4 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/dev/icerock/moko/gradle/HostsPublicationPlugin.kt create mode 100644 src/main/kotlin/dev/icerock/moko/gradle/JvmPlugin.kt diff --git a/build.gradle.kts b/build.gradle.kts index bc10be9..c0261a5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -78,6 +78,11 @@ gradlePlugin { implementationClass = "dev.icerock.moko.gradle.NexusPublicationPlugin" } + create("publication-hosts") { + id = "dev.icerock.moko.gradle.publication.hosts" + implementationClass = "dev.icerock.moko.gradle.HostsPublicationPlugin" + } + create("stubjavadoc") { id = "dev.icerock.moko.gradle.stub.javadoc" implementationClass = "dev.icerock.moko.gradle.StubJavaDocPlugin" @@ -87,6 +92,11 @@ gradlePlugin { id = "dev.icerock.moko.gradle.tests" implementationClass = "dev.icerock.moko.gradle.TestsReportPlugin" } + + create("jvm") { + id = "dev.icerock.moko.gradle.jvm" + implementationClass = "dev.icerock.moko.gradle.JvmPlugin" + } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9e3d2a8..d4bb27b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -mokoGradlePluginVersion = "0.1.1" +mokoGradlePluginVersion = "0.2.0" kotlinVersion = "1.6.10" androidGradlePluginVerison = "7.0.4" diff --git a/src/main/kotlin/dev/icerock/moko/gradle/HostsPublicationPlugin.kt b/src/main/kotlin/dev/icerock/moko/gradle/HostsPublicationPlugin.kt new file mode 100644 index 0000000..0874655 --- /dev/null +++ b/src/main/kotlin/dev/icerock/moko/gradle/HostsPublicationPlugin.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.gradle + +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.maven.tasks.AbstractPublishToMaven +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.withType + +class HostsPublicationPlugin : Plugin { + + override fun apply(target: Project) { + target.plugins.withId("org.gradle.maven-publish") { + target.configure { + val publicationsFromMainHost = listOf( + "wasm32", + "jvm", + "js", + "kotlinMultiplatform", + "androidRelease", + "androidDebug", + "linuxArm64", + "linuxArm32Hfp", + "linuxX64" + ) + + target.tasks.withType() + .matching { it.publication?.name in publicationsFromMainHost } + .configureEach { onlyIf { System.getProperty("IS_MAIN_HOST") == "true" } } + } + } + } +} diff --git a/src/main/kotlin/dev/icerock/moko/gradle/JvmPlugin.kt b/src/main/kotlin/dev/icerock/moko/gradle/JvmPlugin.kt new file mode 100644 index 0000000..705635d --- /dev/null +++ b/src/main/kotlin/dev/icerock/moko/gradle/JvmPlugin.kt @@ -0,0 +1,46 @@ +/* + * Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. + */ + +package dev.icerock.moko.gradle + +import org.gradle.api.JavaVersion +import org.gradle.api.Plugin +import org.gradle.api.Project +import org.gradle.api.plugins.JavaPluginExtension +import org.gradle.api.publish.PublishingExtension +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.kotlin.dsl.configure +import org.gradle.kotlin.dsl.get +import org.gradle.kotlin.dsl.register +import org.gradle.kotlin.dsl.withType +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +class JvmPlugin : Plugin { + override fun apply(target: Project) { + with(target.plugins) { + apply("org.jetbrains.kotlin.jvm") + } + + target.configure { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + withJavadocJar() + withSourcesJar() + } + + target.tasks + .withType() + .configureEach { + kotlinOptions.jvmTarget = "1.8" + } + + target.plugins.withId("org.gradle.maven-publish") { + target.configure { + publications.register("mavenJava", MavenPublication::class) { + from(target.components["java"]) + } + } + } + } +}