Skip to content

Commit

Permalink
Fixes to Gradle config to ensure we can publish 0.1.1 (#237)
Browse files Browse the repository at this point in the history
* Gradle config to ensure we can publish

* Fix pom packageing type. should be AAR thanks Niall
  • Loading branch information
scottyab authored Sep 18, 2024
1 parent 269dac8 commit 8e8bc3c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 46 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ android {

dependencies {
implementation(project(":rootbeerlib"))
// used when testing the snapshot lib
// implementation("com.scottyab:rootbeer-lib:0.1.1-SNAPSHOT")

implementation(libs.kotlin.stdlib)
implementation(libs.kotlin.coroutines.core)
Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ kotlin.code.style=official
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
# Maven details
# Maven details, note NEXUS_USERNAME and NEXUS_PASSWORD are not defined here in git, they are
# private to the author.
VERSION_NAME=0.1.1
VERSION_CODE=11
GROUP=com.scottyab
POM_DESCRIPTION=A tasty root checker library and sample app. We've scoured the internets for different methods of answering that age old question... Has this device got root?
POM_DESCRIPTION=A tasty root checker library. We've scoured the internets for different methods of answering that age old question... Has this device got root?
POM_URL=https://github.com/scottyab/rootbeer.git
POM_SCM_URL=https://github.com/scottyab/rootbeer.git
POM_SCM_CONNECTION=scm:[email protected]:scottyab/rootbeer.git
Expand Down
69 changes: 27 additions & 42 deletions rootbeerlib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ android {
publishing {
singleVariant("release") {
withSourcesJar()
withJavadocJar()
}
}
}
Expand All @@ -76,80 +77,64 @@ dependencies {
testImplementation(libs.mockito)
}

fun getPropertyOrDefault(
propertyName: String,
default: String = "",
): String = project.findProperty(propertyName)?.toString() ?: default
// helper method to ensure we have a non null string for a property
fun getPropertyOrEmpty(propertyName: String): String = project.findProperty(propertyName)?.toString().orEmpty()

project.version = getPropertyOrDefault(propertyName = "VERSION_NAME")
project.group = getPropertyOrDefault(propertyName = "GROUP")
project.version = getPropertyOrEmpty("VERSION_NAME")
project.group = getPropertyOrEmpty("GROUP")

fun isReleaseBuild(): Boolean = !getPropertyOrDefault(propertyName = "VERSION_NAME").contains("SNAPSHOT")
fun isReleaseBuild(): Boolean = !getPropertyOrEmpty("VERSION_NAME").contains("SNAPSHOT")

fun getReleaseRepositoryUrl(): String =
getPropertyOrDefault(
propertyName = "RELEASE_REPOSITORY_URL",
default = "https://oss.sonatype.org/service/local/staging/deploy/maven2/",
)
fun getReleaseRepositoryUrl(): String = getPropertyOrEmpty("RELEASE_REPOSITORY_URL")

fun getSnapshotRepositoryUrl(): String =
getPropertyOrDefault(
propertyName = "SNAPSHOT_REPOSITORY_URL",
default = "https://oss.sonatype.org/content/repositories/snapshots/",
)
fun getSnapshotRepositoryUrl(): String = getPropertyOrEmpty("SNAPSHOT_REPOSITORY_URL")

fun getRepositoryUsername(): String = getPropertyOrDefault(propertyName = "NEXUS_USERNAME")
fun getRepositoryUsername(): String = getPropertyOrEmpty("NEXUS_USERNAME")

fun getRepositoryPassword(): String = getPropertyOrDefault(propertyName = "NEXUS_PASSWORD")
fun getRepositoryPassword(): String = getPropertyOrEmpty("NEXUS_PASSWORD")

publishing {
publications {
register<MavenPublication>("release") {
groupId = getPropertyOrDefault("GROUP")
artifactId = getPropertyOrDefault("POM_ARTIFACT_ID")
version = getPropertyOrDefault("VERSION_NAME")
groupId = getPropertyOrEmpty("GROUP")
artifactId = getPropertyOrEmpty("POM_ARTIFACT_ID")
version = getPropertyOrEmpty("VERSION_NAME")
afterEvaluate {
from(components["release"])
}

pom {
name = getPropertyOrDefault("POM_NAME")
packaging = getPropertyOrDefault("POM_PACKAGING")
description = getPropertyOrDefault("POM_DESCRIPTION")
url = getPropertyOrDefault("POM_URL")
name = getPropertyOrEmpty("POM_NAME")
packaging = getPropertyOrEmpty("POM_PACKAGING")
description = getPropertyOrEmpty("POM_DESCRIPTION")
url = getPropertyOrEmpty("POM_URL")

scm {
url = getPropertyOrDefault("POM_SCM_URL")
connection = getPropertyOrDefault("POM_SCM_CONNECTION")
developerConnection = getPropertyOrDefault("POM_SCM_DEV_CONNECTION")
url = getPropertyOrEmpty("POM_SCM_URL")
connection = getPropertyOrEmpty("POM_SCM_CONNECTION")
developerConnection = getPropertyOrEmpty("POM_SCM_DEV_CONNECTION")
}

licenses {
license {
name = getPropertyOrDefault("POM_LICENCE_NAME")
url = getPropertyOrDefault("POM_LICENCE_URL")
distribution = getPropertyOrDefault("POM_LICENCE_DIST")
name = getPropertyOrEmpty("POM_LICENCE_NAME")
url = getPropertyOrEmpty("POM_LICENCE_URL")
distribution = getPropertyOrEmpty("POM_LICENCE_DIST")
}
}

developers {
developer {
id = getPropertyOrDefault("POM_DEVELOPER_ID")
name = getPropertyOrDefault("POM_DEVELOPER_NAME")
id = getPropertyOrEmpty("POM_DEVELOPER_ID")
name = getPropertyOrEmpty("POM_DEVELOPER_NAME")
organizationUrl = getPropertyOrEmpty("POM_URL")
}
}
}
}
}
repositories {
maven(url = getReleaseRepositoryUrl()) {
credentials {
username = getRepositoryUsername()
password = getRepositoryPassword()
}
}
maven(url = getSnapshotRepositoryUrl()) {
name = "snapshot"
maven(url = if (isReleaseBuild()) getReleaseRepositoryUrl() else getSnapshotRepositoryUrl()) {
credentials {
username = getRepositoryUsername()
password = getRepositoryPassword()
Expand Down
2 changes: 1 addition & 1 deletion rootbeerlib/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Module Gradle settings.
POM_NAME=rootbeer
POM_ARTIFACT_ID=rootbeer-lib
POM_PACKAGING=jar
POM_PACKAGING=aar
6 changes: 5 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven {
name = "Snapshot"
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
}
}
}

rootProject.name = "RootChecker"
include(":app", ":rootbeerlib")
include(":app", ":rootbeerlib")

0 comments on commit 8e8bc3c

Please sign in to comment.