Skip to content

Instantly share code, notes, and snippets.

@SergeiMikhailovskii
Created March 29, 2024 20:47
Show Gist options
  • Save SergeiMikhailovskii/f9fb93521d3d00c13837384df1fa42da to your computer and use it in GitHub Desktop.
Save SergeiMikhailovskii/f9fb93521d3d00c13837384df1fa42da to your computer and use it in GitHub Desktop.
class KMPModuleConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply(extensions.getPluginId("androidLibrary"))
apply(extensions.getPluginId("kotlinMultiplatform"))
apply("maven-publish")
}
group = "com.mikhailovskii.kmp"
version = System.getenv("LIBRARY_VERSION") ?: extensions.getVersion("pluginVersion")
extensions.configure<KotlinMultiplatformExtension> {
androidTarget { publishLibraryVariants("release", "debug") }
iosX64()
iosArm64()
iosSimulatorArm64()
applyDefaultHierarchyTemplate()
jvmToolchain(17)
}
extensions.configure<LibraryExtension> {
namespace = "com.mikhailovskii.inappreview"
compileSdk = 34
defaultConfig {
minSdk = 21
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
}
extensions.configure<PublishingExtension> {
publications {
matching {
return@matching it.name in listOf(
"iosArm64",
"iosX64",
"kotlinMultiplatform"
)
}.all {
tasks.withType<AbstractPublishToMaven>()
.matching { it.publication == this@all }
.configureEach { onlyIf { findProperty("isMainHost") == "true" } }
}
}
repositories {
maven {
url = uri("https://maven.pkg.github.com/SergeiMikhailovskii/kmp-app-review")
credentials {
username = System.getenv("GITHUB_USER")
password = System.getenv("GITHUB_API_KEY")
}
}
}
}
tasks.register("buildAndPublish", DefaultTask::class) {
dependsOn("build")
dependsOn("publish")
tasks.findByPath("publish")?.mustRunAfter("build")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment