Skip to content

Commit

Permalink
Convert dachlatten-text to pure Kotlin lib
Browse files Browse the repository at this point in the history
  • Loading branch information
janseeger committed Feb 22, 2024
1 parent c88275c commit d5bded5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
4 changes: 4 additions & 0 deletions build-logic/android-library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@ gradlePlugin {
id = "android-library-robolectric-test"
implementationClass = "AndroidLibraryRobolectricTestPlugin"
}
register("kotliLibrary") {
id = "kotlin-library"
implementationClass = "KotlinLibraryPlugin"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import com.android.build.gradle.LibraryExtension
import java.io.File
import java.util.Properties
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.component.SoftwareComponent
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.provideDelegate
import org.gradle.kotlin.dsl.register
import org.gradle.plugins.signing.SigningExtension
import java.io.File
import java.util.Properties

class AndroidLibraryReleasePlugin : Plugin<Project> {
override fun apply(target: Project) {
Expand All @@ -21,7 +22,9 @@ class AndroidLibraryReleasePlugin : Plugin<Project> {

setupReleaseBuild()
setupVersionInfo()
setupPublishing()
afterEvaluate {
setupPublishing(components["release"])
}
setupSigning()
}
}
Expand All @@ -41,7 +44,7 @@ private fun Project.setupReleaseBuild() {
}
}

private fun Project.setupVersionInfo() {
internal fun Project.setupVersionInfo() {
val versionProperties = File(project.rootDir, "version.properties")
versionProperties.inputStream().use { inputStream ->
Properties().apply {
Expand All @@ -51,14 +54,14 @@ private fun Project.setupVersionInfo() {
}
}

private fun Properties.getVersionName(): String {
internal fun Properties.getVersionName(): String {
val major = (get("majorVersion") as String).toInt()
val minor = (get("minorVersion") as String).toInt()
val patch = (get("patchVersion") as String).toInt()
return "$major.$minor.$patch"
}

private fun Project.setupPublishing() {
internal fun Project.setupPublishing(component: SoftwareComponent) {
extensions.configure<PublishingExtension> {
publications {
register<MavenPublication>("release") {
Expand All @@ -68,9 +71,7 @@ private fun Project.setupPublishing() {

setPom()

afterEvaluate {
from(components["release"])
}
from(component)
}
}

Expand All @@ -87,7 +88,7 @@ private fun Project.setupPublishing() {
}
}

private fun MavenPublication.setPom() {
internal fun MavenPublication.setPom() {
pom {
name.set("Dachlatten-flow")
description.set("")
Expand All @@ -106,7 +107,7 @@ private fun MavenPublication.setPom() {
}
}

private fun Project.setupSigning() {
fun Project.setupSigning() {
extensions.configure<SigningExtension> {
val signingKey: String? by project
val signingPassword: String? by project
Expand Down
21 changes: 21 additions & 0 deletions build-logic/android-library/src/main/kotlin/KotlinLibraryPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.get

class KotlinLibraryPlugin: Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("org.jetbrains.kotlin.jvm")
apply("maven-publish")
apply("signing")
}

setupVersionInfo()
afterEvaluate {
setupPublishing(components["java"])
}
setupSigning()
}
}
}
4 changes: 1 addition & 3 deletions dachlatten-text/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
plugins {
id("android-library-base")
id("android-library-unit-test")
id("android-library-release")
id("kotlin-library")
}

dependencies {
Expand Down

0 comments on commit d5bded5

Please sign in to comment.