Skip to content

Commit

Permalink
new hosts and jvm plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex009 committed Aug 7, 2022
1 parent 8bc1d5e commit 418a72b
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 1 deletion.
10 changes: 10 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
mokoGradlePluginVersion = "0.1.1"
mokoGradlePluginVersion = "0.2.0"

kotlinVersion = "1.6.10"
androidGradlePluginVerison = "7.0.4"
Expand Down
37 changes: 37 additions & 0 deletions src/main/kotlin/dev/icerock/moko/gradle/HostsPublicationPlugin.kt
Original file line number Diff line number Diff line change
@@ -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<Project> {

override fun apply(target: Project) {
target.plugins.withId("org.gradle.maven-publish") {
target.configure<PublishingExtension> {
val publicationsFromMainHost = listOf(
"wasm32",
"jvm",
"js",
"kotlinMultiplatform",
"androidRelease",
"androidDebug",
"linuxArm64",
"linuxArm32Hfp",
"linuxX64"
)

target.tasks.withType<AbstractPublishToMaven>()
.matching { it.publication?.name in publicationsFromMainHost }
.configureEach { onlyIf { System.getProperty("IS_MAIN_HOST") == "true" } }
}
}
}
}
46 changes: 46 additions & 0 deletions src/main/kotlin/dev/icerock/moko/gradle/JvmPlugin.kt
Original file line number Diff line number Diff line change
@@ -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<Project> {
override fun apply(target: Project) {
with(target.plugins) {
apply("org.jetbrains.kotlin.jvm")
}

target.configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withJavadocJar()
withSourcesJar()
}

target.tasks
.withType<KotlinCompile>()
.configureEach {
kotlinOptions.jvmTarget = "1.8"
}

target.plugins.withId("org.gradle.maven-publish") {
target.configure<PublishingExtension> {
publications.register("mavenJava", MavenPublication::class) {
from(target.components["java"])
}
}
}
}
}

0 comments on commit 418a72b

Please sign in to comment.