Skip to content

Commit 38f33eb

Browse files
feat(build): add Sonatype repositories and Nexus publishing plugin
• Add mavenCentral() and sonatype repositories • Configure Nexus publishing with credentials • Introduce NexusPublishing task to ship the Android SDK
1 parent 841a5d2 commit 38f33eb

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

android-sdk/build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ android {
5959
}
6060
}
6161

62+
repositories {
63+
maven {
64+
url "https://central.sonatype.com/repository/maven-snapshots/"
65+
}
66+
mavenCentral()
67+
}
68+
6269
dependencies {
6370
api project(':shared')
6471
api project(':datafile-handler')
@@ -68,7 +75,6 @@ dependencies {
6875
api ("com.optimizely.ab:core-api:$java_core_ver") {
6976
exclude group: 'com.google.code.findbugs'
7077
}
71-
7278
implementation "org.slf4j:slf4j-api:$slf4j_ver"
7379

7480
compileOnly "com.fasterxml.jackson.core:jackson-databind:$jacksonversion"

build.gradle

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ buildscript {
2626
ext.is_release_version = !version_name.endsWith("SNAPSHOT")
2727

2828
repositories {
29-
jcenter()
3029
google()
30+
mavenCentral()
3131
}
3232
dependencies {
3333
classpath 'com.android.tools.build:gradle:7.2.2'
@@ -39,7 +39,8 @@ buildscript {
3939
}
4040

4141
plugins {
42-
id "org.jlleitschuh.gradle.ktlint" version "11.0.0"
42+
id "org.jlleitschuh.gradle.ktlint" version "11.0.0"
43+
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0'
4344
}
4445

4546
allprojects {
@@ -52,11 +53,10 @@ allprojects {
5253
}
5354

5455
repositories {
55-
jcenter()
5656
google()
5757
mavenCentral()
5858
// SNAPSHOT support
59-
maven {url "https://oss.sonatype.org/content/repositories/snapshots/" }
59+
maven { url "https://central.sonatype.com/repository/maven-snapshots/" }
6060
maven { url "https://jitpack.io" }
6161
}
6262

@@ -117,9 +117,35 @@ task testODPModule () {
117117
}
118118

119119
// Publish to MavenCentral
120+
nexusPublishing {
121+
packageGroup = group_id
122+
repositories {
123+
sonatype {
124+
nexusUrl.set(uri('https://ossrh-staging-api.central.sonatype.com/service/local/'))
125+
snapshotRepositoryUrl.set(uri('https://central.sonatype.com/repository/maven-snapshots/'))
126+
username = System.getenv('MAVEN_CENTRAL_USERNAME')
127+
password = System.getenv('MAVEN_CENTRAL_PASSWORD')
128+
}
129+
}
130+
131+
}
120132

121133
task ship() {
122134
dependsOn(':android-sdk:ship', ':shared:ship', ':event-handler:ship', ':user-profile:ship', ':datafile-handler:ship', ':odp:ship')
135+
doLast {
136+
def sonatypeTasks = ['publishToSonatype']
137+
if (is_release_version) {
138+
sonatypeTasks.add('closeSonatypeStagingRepository')
139+
}
140+
141+
def args = ['./gradlew']
142+
args.addAll(sonatypeTasks)
143+
args.add('--info')
144+
145+
exec {
146+
commandLine args
147+
}
148+
}
123149
}
124150

125151
def publishedProjects = subprojects.findAll { it.name != 'test-app' }
@@ -223,17 +249,6 @@ configure(publishedProjects) {
223249
from components.release
224250
}
225251
}
226-
repositories {
227-
maven {
228-
def releaseUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2"
229-
def snapshotUrl = "https://oss.sonatype.org/content/repositories/snapshots"
230-
url = is_release_version ? releaseUrl : snapshotUrl
231-
credentials {
232-
username System.getenv('MAVEN_CENTRAL_USERNAME')
233-
password System.getenv('MAVEN_CENTRAL_PASSWORD')
234-
}
235-
}
236-
}
237252
}
238253

239254
signing {

0 commit comments

Comments
 (0)