build: improve maven publication
authorDa Risk <da_risk@geekorum.com>
Thu, 01 Dec 2022 17:20:38 -0400
changeset 32 f165a9538ee3
parent 31 0e233781410b
child 33 6291c6dab84b
build: improve maven publication
buildSrc/src/main/kotlin/VersionAlignment.kt
config/android-maven-publication.gradle
geekdroid-firebase/build.gradle.kts
geekdroid/build.gradle.kts
--- a/buildSrc/src/main/kotlin/VersionAlignment.kt	Tue Nov 29 19:38:26 2022 -0400
+++ b/buildSrc/src/main/kotlin/VersionAlignment.kt	Thu Dec 01 17:20:38 2022 -0400
@@ -50,8 +50,8 @@
     open class AlignmentRule : SameGroupAlignmentRule(platformName, "com.google.dagger")
 }
 
-fun DependencyHandler.enforcedDaggerPlatform(version: String): Dependency {
-    return enforcedPlatform("${components.getOrCreatePlatform(DaggerPlatform)}:$version")
+fun DependencyHandler.daggerPlatform(version: String): Dependency {
+    return platform("${components.getOrCreatePlatform(DaggerPlatform)}:$version")
 }
 
 open class PlatformFactory(
--- a/config/android-maven-publication.gradle	Tue Nov 29 19:38:26 2022 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-/*
- * Geekdroid is a utility library for development on the Android
- * Platform.
- *
- * Copyright (C) 2017-2022 by Frederic-Charles Barthelery.
- *
- * This file is part of Geekdroid.
- *
- * Geekdroid is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Geekdroid is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Geekdroid.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- * This configuration allows to publish android libraries into a maven repository.
- * You need to define in your build.gradle the following variables :
- * version = "1.0"                // the version of your projects
- * ext.artifactId="geny-widgets"  // the maven artifact id
- * Use ./gradlew tasks to see the name of the publishing tasks.
- */
-if (plugins.hasPlugin("com.android.library")) {
-
-    apply plugin: 'maven-publish'
-
-    if (!project.ext.properties.containsKey("artifactId")) {
-        ext.artifactId = project.name
-    }
-
-    publishing {
-        publications {
-            projectRelease(MavenPublication) {
-                artifactId project.artifactId
-                artifact "build/outputs/aar/${project.archivesBaseName}-release.aar"
-            }
-
-            projectSnapshot(MavenPublication) {
-                artifactId project.artifactId
-                artifact "build/outputs/aar/${project.archivesBaseName}-debug.aar"
-                version getVersion() + "-SNAPSHOT"
-            }
-        }
-    }
-
-    tasks.named("publishProjectReleasePublicationToMavenLocal") {
-        dependsOn "assembleRelease"
-    }
-
-    tasks.named("publishProjectSnapshotPublicationToMavenLocal") {
-        dependsOn "assembleDebug"
-    }
-}
--- a/geekdroid-firebase/build.gradle.kts	Tue Nov 29 19:38:26 2022 -0400
+++ b/geekdroid-firebase/build.gradle.kts	Thu Dec 01 17:20:38 2022 -0400
@@ -8,9 +8,6 @@
     `maven-publish`
 }
 
-val archivesBaseName by extra("geekdroid-firebase")
-val artifactId by extra (archivesBaseName)
-
 android {
     val compileSdkInt: Int by rootProject.extra
     compileSdk = compileSdkInt
@@ -33,13 +30,22 @@
         abortOnError = false
     }
 
+    publishing {
+        singleVariant("release") {
+            withSourcesJar()
+        }
+        singleVariant("debug") {
+            withSourcesJar()
+        }
+    }
+
 }
 
 dependencies {
-    implementation(enforcedPlatform(kotlin("bom")))
+    implementation(platform(kotlin("bom")))
     implementation(kotlin("stdlib-jdk8"))
 
-    implementation(enforcedPlatform("org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.4"))
+    implementation(platform("org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.4"))
     api("org.jetbrains.kotlinx:kotlinx-coroutines-core")
     api("org.jetbrains.kotlinx:kotlinx-coroutines-play-services")
 
@@ -65,5 +71,39 @@
 
 apply {
     from("$projectDir/../config/source-archive.gradle")
-    from("$projectDir/../config/android-maven-publication.gradle")
 }
+
+publishing {
+    publications {
+        val pomConfiguration: (MavenPom).() -> Unit = {
+            name.set("Geekdroid-Firebase")
+            description.set("An Android library used in various Android projects. ")
+            licenses {
+                license {
+                    name.set("GPL-3.0-or-later")
+                    url.set("https://www.gnu.org/licenses/gpl-3.0.html")
+                    distribution.set("repo")
+                }
+            }
+            inceptionYear.set("2017")
+        }
+
+        register<MavenPublication>("release") {
+            afterEvaluate {
+                from(components["release"])
+            }
+            artifactId = "geekdroid-firebase"
+            pom(pomConfiguration)
+        }
+
+        register<MavenPublication>("debugSnapshot") {
+            afterEvaluate {
+                from(components["debug"])
+            }
+            artifactId = "geekdroid-firebase"
+            version = "$version-SNAPSHOT"
+            pom(pomConfiguration)
+
+        }
+    }
+}
--- a/geekdroid/build.gradle.kts	Tue Nov 29 19:38:26 2022 -0400
+++ b/geekdroid/build.gradle.kts	Thu Dec 01 17:20:38 2022 -0400
@@ -20,7 +20,7 @@
  * along with Geekdroid.  If not, see <http://www.gnu.org/licenses/>.
  */
 import com.geekorum.build.configureJavaVersion
-import com.geekorum.build.enforcedDaggerPlatform
+import com.geekorum.build.daggerPlatform
 
 plugins {
     id("com.android.library")
@@ -31,8 +31,6 @@
     `maven-publish`
 }
 
-val archivesBaseName by extra("geekdroid")
-val artifactId by extra (archivesBaseName)
 
 android {
     val compileSdkInt: Int by rootProject.extra
@@ -60,6 +58,14 @@
         enable = true
     }
 
+    publishing {
+        singleVariant("release") {
+            withSourcesJar()
+        }
+        singleVariant("debug") {
+            withSourcesJar()
+        }
+    }
 }
 
 dependencies {
@@ -77,15 +83,15 @@
     implementation("com.squareup.okhttp3:okhttp:4.10.0")
 
     val daggerVersion = "2.44.1"
-    implementation(enforcedDaggerPlatform(daggerVersion))
-    kapt(enforcedDaggerPlatform(daggerVersion))
+    implementation(daggerPlatform(daggerVersion))
+    kapt(daggerPlatform(daggerVersion))
     implementation("com.google.dagger:dagger:$daggerVersion")
     kapt("com.google.dagger:dagger-compiler:$daggerVersion")
 
-    implementation(enforcedPlatform(kotlin("bom")))
+    implementation(platform(kotlin("bom")))
     implementation(kotlin("stdlib-jdk8"))
 
-    implementation(enforcedPlatform("org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.4"))
+    implementation(platform("org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.4"))
     implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core")
 
     implementation("androidx.lifecycle:lifecycle-livedata-core-ktx:2.5.1")
@@ -102,5 +108,39 @@
 
 apply {
     from("$projectDir/../config/source-archive.gradle")
-    from("$projectDir/../config/android-maven-publication.gradle")
 }
+
+publishing {
+    publications {
+        val pomConfiguration: (MavenPom).() -> Unit = {
+            name.set("Geekdroid")
+            description.set("An Android library used in various Android projects. ")
+            licenses {
+                license {
+                    name.set("GPL-3.0-or-later")
+                    url.set("https://www.gnu.org/licenses/gpl-3.0.html")
+                    distribution.set("repo")
+                }
+            }
+            inceptionYear.set("2017")
+        }
+
+        register<MavenPublication>("release") {
+            afterEvaluate {
+                from(components["release"])
+            }
+            artifactId = "geekdroid"
+            pom(pomConfiguration)
+        }
+
+        register<MavenPublication>("debugSnapshot") {
+            afterEvaluate {
+                from(components["debug"])
+            }
+            artifactId = "geekdroid"
+            version = "$version-SNAPSHOT"
+            pom(pomConfiguration)
+
+        }
+    }
+}