Skip to content

Commit

Permalink
Prepare for maven publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Thanos Psaridis committed Sep 19, 2021
1 parent 9b04c15 commit ec4d278
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 10 deletions.
28 changes: 21 additions & 7 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
plugins {
base
`java-gradle-plugin`
`kotlin-dsl`
}

allprojects {
repositories {
mavenCentral()
gradlePluginPortal()
}
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

repositories {
//google()
gradlePluginPortal()
mavenCentral()
}

dependencies {
testImplementation(gradleTestKit())
testImplementation("junit:junit:4.13.2")

}

tasks.withType<Test>().configureEach {
testLogging { showStandardStreams = true }
}
44 changes: 43 additions & 1 deletion buildSrc/src/main/kotlin/Artifact.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import org.gradle.api.Project
import java.util.*
import kotlin.collections.LinkedHashMap

object Artifact {

val ARTIFACT_NAME = "wifiutils"
Expand All @@ -6,6 +10,8 @@ object Artifact {
val VERSION_CODE = 22
val POM_URL = "https://github.com/ThanosFisherman/WifiUtils"
val POM_SCM_URL = "https://github.com/ThanosFisherman/WifiUtils"
val POM_SCM_CONNECTION = "scm:git:github.com/ThanosFisherman/WifiUtils.git"
val POM_SCM_DEV_CONNECTION = "scm:git:ssh://github.com/ThanosFisherman/WifiUtils.git"
val POM_ISSUE_URL = "https://github.com/ThanosFisherman/WifiUtils/issues"
val POM_DESC = "Library that makes it easy to Connect to WiFi hotspots using ssid and/or bssid"

Expand All @@ -21,4 +27,40 @@ object Artifact {

val POM_DEVELOPER_ID = "thanosfisherman"
val POM_DEVELOPER_NAME = "Thanos Psaridis"
}
val DEVELOPER_EMAIL = "[email protected]"

val RELEASE_REPO_URL = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
val SNAPSHOT_REPO_URL = "https://oss.sonatype.org/content/repositories/snapshots"
val REPO_NAME = "sonatype"
}


val Project.credentialsMap: Map<String, String>
inline get() =
LinkedHashMap<String, String>().apply {

val propertiesFile = rootProject.file("local.properties")
if (propertiesFile.exists() && propertiesFile.canRead()) {
try {
val properties = Properties()
properties.load(propertiesFile.inputStream())
this["signing.keyId"] = properties.getProperty("signing.keyId")
this["signing.password"] = properties.getProperty("signing.password")
this["signing.secretKeyRingFile"] =
properties.getProperty("signing.secretKeyRingFile")
this["ossrhUsername"] = properties.getProperty("ossrhUsername")
this["ossrhPassword"] = properties.getProperty("ossrhPassword")
this["sonatypeStagingProfileId"] =
properties.getProperty("sonatypeStagingProfileId")
} catch (e: Exception) {}
} else {
this["signing.keyId"] = System.getenv("signing.keyId")
this["signing.password"] = System.getenv("signing.password")
this["signing.secretKeyRingFile"] = System.getenv("signing.secretKeyRingFile")
this["ossrhUsername"] = System.getenv("ossrhUsername")
this["ossrhPassword"] = System.getenv("ossrhPassword")
this["sonatypeStagingProfileId"] = System.getenv("sonatypeStagingProfileId")
//val keystoreFile = project.rootProject.file(rootDir.path + File.separator + System.getenv("keystore_name"))
}
}

117 changes: 115 additions & 2 deletions wifiutils/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import java.util.*

plugins {
id(GradlePluginId.ANDROID_LIBRARY)
kotlin("android")
// Documentation for our code
id(GradlePluginId.DOKKA) version GradlePluginVersion.DOKKA_VERSION
// Maven publication
`maven-publish`
signing
}

android {
Expand Down Expand Up @@ -49,3 +48,117 @@ dependencies {
//addTestDependencies()
}

val dokkaTask by tasks.creating(org.jetbrains.dokka.gradle.DokkaTask::class) {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles Kotlin docs with Dokka"
outputDirectory.set(File("$buildDir/dokka"))
//documentationFileName.set("README.md")
}

val dokkaJar by tasks.creating(Jar::class) {
archiveClassifier.set("dokka")
from("$buildDir/dokka")
dependsOn(dokkaTask)
}

val sourcesJar by tasks.creating(Jar::class) {
archiveClassifier.set("sources")
if (project.plugins.findPlugin("com.android.library") != null) {
from(android.sourceSets.getByName("main").java.srcDirs)
} else {
from(sourceSets.getByName("main").java.srcDirs)
}
}

artifacts {
archives(sourcesJar)
archives(dokkaJar)
}

credentialsMap.forEach { extra.set(it.key, it.value) }

publishing {
publications {
create<MavenPublication>(Artifact.ARTIFACT_NAME) {
groupId = Artifact.ARTIFACT_GROUP
artifactId = Artifact.ARTIFACT_NAME
version = Artifact.VERSION_NAME

if (project.plugins.findPlugin("com.android.library") != null) {
artifact("$buildDir/outputs/aar/${project.name}-release.aar")
} else {
from(components["java"])
//artifact("$buildDir/libs/${project.getName()}-${version}.jar")
}
artifacts {
artifact(sourcesJar)
artifact(dokkaJar)
}

pom {
name.set(Artifact.LIBRARY_NAME)
description.set(Artifact.POM_DESC)
url.set(Artifact.POM_URL)
licenses {
license {
name.set(Artifact.POM_LICENSE_NAME)
url.set(Artifact.POM_LICENSE_URL)
distribution.set(Artifact.POM_URL)
}
}
developers {
developer {
id.set(Artifact.POM_DEVELOPER_ID)
name.set(Artifact.POM_DEVELOPER_NAME)
email.set(Artifact.DEVELOPER_EMAIL)
}
}
scm {
connection.set(Artifact.POM_SCM_CONNECTION)
developerConnection.set(Artifact.POM_SCM_DEV_CONNECTION)
url.set(Artifact.POM_SCM_URL)
}
repositories {
maven {
// change URLs to point to your repos, e.g. http://my.org/repo
val releasesRepoUrl = uri(Artifact.RELEASE_REPO_URL)
val snapshotsRepoUrl = uri(Artifact.SNAPSHOT_REPO_URL)
name = Artifact.REPO_NAME
url = if (version.toString()
.endsWith("SNAPSHOT")
) snapshotsRepoUrl else releasesRepoUrl
credentials {
username = credentialsMap["ossrhUsername"]
password = credentialsMap["ossrhPassword"]
}
}
}

// hack if you wanna include any transitive dependencies. I'm a hackur indeed
/* withXml {
asNode().apply {
appendNode("description", Artifact.POM_DESC)
appendNode("name", Artifact.LIBRARY_NAME)
appendNode("url", Artifact.POM_URL)
appendNode("licenses").appendNode("license").apply {
appendNode("name", Artifact.POM_LICENSE_NAME)
appendNode("url", Artifact.POM_LICENSE_URL)
appendNode("distribution", Artifact.POM_LICENSE_DIST)
}
appendNode("developers").appendNode("developer").apply {
appendNode("id", Artifact.POM_DEVELOPER_ID)
appendNode("name", Artifact.POM_DEVELOPER_NAME)
}
appendNode("scm").apply {
appendNode("url", Artifact.POM_SCM_URL)
}
}
}*/
}
}
}
}

signing {
sign(publishing.publications[Artifact.ARTIFACT_NAME])
}

0 comments on commit ec4d278

Please sign in to comment.