Skip to content

Commit 8e8bc3c

Browse files
authored
Fixes to Gradle config to ensure we can publish 0.1.1 (#237)
* Gradle config to ensure we can publish * Fix pom packageing type. should be AAR thanks Niall
1 parent 269dac8 commit 8e8bc3c

File tree

5 files changed

+38
-46
lines changed

5 files changed

+38
-46
lines changed

app/build.gradle.kts

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ android {
7171

7272
dependencies {
7373
implementation(project(":rootbeerlib"))
74+
// used when testing the snapshot lib
75+
// implementation("com.scottyab:rootbeer-lib:0.1.1-SNAPSHOT")
7476

7577
implementation(libs.kotlin.stdlib)
7678
implementation(libs.kotlin.coroutines.core)

gradle.properties

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ kotlin.code.style=official
2323
# resources declared in the library itself and none from the library's dependencies,
2424
# thereby reducing the size of the R class for that library
2525
android.nonTransitiveRClass=true
26-
# Maven details
26+
# Maven details, note NEXUS_USERNAME and NEXUS_PASSWORD are not defined here in git, they are
27+
# private to the author.
2728
VERSION_NAME=0.1.1
2829
VERSION_CODE=11
2930
GROUP=com.scottyab
30-
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?
31+
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?
3132
POM_URL=https://github.com/scottyab/rootbeer.git
3233
POM_SCM_URL=https://github.com/scottyab/rootbeer.git
3334
POM_SCM_CONNECTION=scm:[email protected]:scottyab/rootbeer.git

rootbeerlib/build.gradle.kts

+27-42
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ android {
6767
publishing {
6868
singleVariant("release") {
6969
withSourcesJar()
70+
withJavadocJar()
7071
}
7172
}
7273
}
@@ -76,80 +77,64 @@ dependencies {
7677
testImplementation(libs.mockito)
7778
}
7879

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

84-
project.version = getPropertyOrDefault(propertyName = "VERSION_NAME")
85-
project.group = getPropertyOrDefault(propertyName = "GROUP")
83+
project.version = getPropertyOrEmpty("VERSION_NAME")
84+
project.group = getPropertyOrEmpty("GROUP")
8685

87-
fun isReleaseBuild(): Boolean = !getPropertyOrDefault(propertyName = "VERSION_NAME").contains("SNAPSHOT")
86+
fun isReleaseBuild(): Boolean = !getPropertyOrEmpty("VERSION_NAME").contains("SNAPSHOT")
8887

89-
fun getReleaseRepositoryUrl(): String =
90-
getPropertyOrDefault(
91-
propertyName = "RELEASE_REPOSITORY_URL",
92-
default = "https://oss.sonatype.org/service/local/staging/deploy/maven2/",
93-
)
88+
fun getReleaseRepositoryUrl(): String = getPropertyOrEmpty("RELEASE_REPOSITORY_URL")
9489

95-
fun getSnapshotRepositoryUrl(): String =
96-
getPropertyOrDefault(
97-
propertyName = "SNAPSHOT_REPOSITORY_URL",
98-
default = "https://oss.sonatype.org/content/repositories/snapshots/",
99-
)
90+
fun getSnapshotRepositoryUrl(): String = getPropertyOrEmpty("SNAPSHOT_REPOSITORY_URL")
10091

101-
fun getRepositoryUsername(): String = getPropertyOrDefault(propertyName = "NEXUS_USERNAME")
92+
fun getRepositoryUsername(): String = getPropertyOrEmpty("NEXUS_USERNAME")
10293

103-
fun getRepositoryPassword(): String = getPropertyOrDefault(propertyName = "NEXUS_PASSWORD")
94+
fun getRepositoryPassword(): String = getPropertyOrEmpty("NEXUS_PASSWORD")
10495

10596
publishing {
10697
publications {
10798
register<MavenPublication>("release") {
108-
groupId = getPropertyOrDefault("GROUP")
109-
artifactId = getPropertyOrDefault("POM_ARTIFACT_ID")
110-
version = getPropertyOrDefault("VERSION_NAME")
99+
groupId = getPropertyOrEmpty("GROUP")
100+
artifactId = getPropertyOrEmpty("POM_ARTIFACT_ID")
101+
version = getPropertyOrEmpty("VERSION_NAME")
111102
afterEvaluate {
112103
from(components["release"])
113104
}
114105

115106
pom {
116-
name = getPropertyOrDefault("POM_NAME")
117-
packaging = getPropertyOrDefault("POM_PACKAGING")
118-
description = getPropertyOrDefault("POM_DESCRIPTION")
119-
url = getPropertyOrDefault("POM_URL")
107+
name = getPropertyOrEmpty("POM_NAME")
108+
packaging = getPropertyOrEmpty("POM_PACKAGING")
109+
description = getPropertyOrEmpty("POM_DESCRIPTION")
110+
url = getPropertyOrEmpty("POM_URL")
120111

121112
scm {
122-
url = getPropertyOrDefault("POM_SCM_URL")
123-
connection = getPropertyOrDefault("POM_SCM_CONNECTION")
124-
developerConnection = getPropertyOrDefault("POM_SCM_DEV_CONNECTION")
113+
url = getPropertyOrEmpty("POM_SCM_URL")
114+
connection = getPropertyOrEmpty("POM_SCM_CONNECTION")
115+
developerConnection = getPropertyOrEmpty("POM_SCM_DEV_CONNECTION")
125116
}
126117

127118
licenses {
128119
license {
129-
name = getPropertyOrDefault("POM_LICENCE_NAME")
130-
url = getPropertyOrDefault("POM_LICENCE_URL")
131-
distribution = getPropertyOrDefault("POM_LICENCE_DIST")
120+
name = getPropertyOrEmpty("POM_LICENCE_NAME")
121+
url = getPropertyOrEmpty("POM_LICENCE_URL")
122+
distribution = getPropertyOrEmpty("POM_LICENCE_DIST")
132123
}
133124
}
134125

135126
developers {
136127
developer {
137-
id = getPropertyOrDefault("POM_DEVELOPER_ID")
138-
name = getPropertyOrDefault("POM_DEVELOPER_NAME")
128+
id = getPropertyOrEmpty("POM_DEVELOPER_ID")
129+
name = getPropertyOrEmpty("POM_DEVELOPER_NAME")
130+
organizationUrl = getPropertyOrEmpty("POM_URL")
139131
}
140132
}
141133
}
142134
}
143135
}
144136
repositories {
145-
maven(url = getReleaseRepositoryUrl()) {
146-
credentials {
147-
username = getRepositoryUsername()
148-
password = getRepositoryPassword()
149-
}
150-
}
151-
maven(url = getSnapshotRepositoryUrl()) {
152-
name = "snapshot"
137+
maven(url = if (isReleaseBuild()) getReleaseRepositoryUrl() else getSnapshotRepositoryUrl()) {
153138
credentials {
154139
username = getRepositoryUsername()
155140
password = getRepositoryPassword()

rootbeerlib/gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Module Gradle settings.
22
POM_NAME=rootbeer
33
POM_ARTIFACT_ID=rootbeer-lib
4-
POM_PACKAGING=jar
4+
POM_PACKAGING=aar

settings.gradle.kts

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ dependencyResolutionManagement {
1010
repositories {
1111
google()
1212
mavenCentral()
13+
maven {
14+
name = "Snapshot"
15+
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
16+
}
1317
}
1418
}
1519

1620
rootProject.name = "RootChecker"
17-
include(":app", ":rootbeerlib")
21+
include(":app", ":rootbeerlib")

0 commit comments

Comments
 (0)