Skip to content

Commit e2a715c

Browse files
committed
Update publishing to maven cetral
1 parent ca7cb2a commit e2a715c

File tree

2 files changed

+22
-52
lines changed

2 files changed

+22
-52
lines changed

build.gradle

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,28 @@ buildscript {
1313
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
1414
classpath 'gradle.plugin.org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.12.2'
1515
classpath 'com.google.firebase:firebase-crashlytics-gradle:3.0.2'
16+
classpath 'io.github.gradle-nexus:publish-plugin:2.0.0'
1617
//classpath 'com.palantir:jacoco-coverage:0.4.0'
1718
// NOTE: Do not place your application dependencies here; they belong
1819
// in the individual module build.gradle files
1920
}
2021
}
2122

2223
apply plugin: 'com.github.kt3k.coveralls'
24+
apply plugin: 'io.github.gradle-nexus.publish-plugin'
2325
apply from: 'configs.gradle'
2426

27+
nexusPublishing {
28+
repositories {
29+
sonatype {
30+
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
31+
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
32+
username = findProperty('ossrhUsername') ?: System.getenv("OSSRH_USERNAME") ?: ""
33+
password = findProperty('ossrhPassword') ?: System.getenv("OSSRH_PASSWORD") ?: ""
34+
}
35+
}
36+
}
37+
2538
allprojects {
2639
repositories {
2740
maven {

publish.gradle

Lines changed: 9 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,6 @@ afterEvaluate {
2929
}
3030
}
3131

32-
/**
33-
* Retrieves property `ossrhPassword` stored in the gradle.properties file (in project or gradle user-root folder)
34-
* @return
35-
*/
36-
def getOSSRHRepositoryPassword() {
37-
return hasProperty('ossrhPassword') ? ossrhPassword : System.getenv("OSSRH_PASSWORD") != null ? System.getenv("OSSRH_PASSWORD") : ""
38-
}
39-
40-
/**
41-
* Retrieves property `ossrhUsername` stored in the gradle.properties file (in project or gradle user-root folder)
42-
* @return
43-
*/
44-
def getOSSRHRepositoryUsername() {
45-
return hasProperty('ossrhUsername') ? ossrhUsername : System.getenv("OSSRH_USERNAME") != null ? System.getenv("OSSRH_USERNAME") : ""
46-
}
47-
4832
def getGithubPublishUsername() {
4933
return hasProperty('githubUsername') ? githubUsername : System.getenv("GITHUB_USERNAME") != null ? System.getenv("GITHUB_USERNAME") : ""
5034
}
@@ -53,15 +37,15 @@ def getGithubPackagesAccessToken() {
5337
return hasProperty('githubAccessToken') ? githubAccessToken : System.getenv("GITHUB_ACCESS_TOKEN") != null ? System.getenv("GITHUB_ACCESS_TOKEN") : ""
5438
}
5539

56-
static def getDate() {
57-
return new Date().format('yyyy-MM-dd HH:mm:ss')
58-
}
59-
6040

6141
/**
62-
* Run ./gradlew :utils:clean && ./gradlew :utils:assembleRelease && ./gradlew :utils:publish
63-
* Run ./gradlew :library:clean && ./gradlew :library:assembleRelease && ./gradlew :library:publish
64-
* This publishes to all production artefact repositories
42+
* GitHub Packages:
43+
* Run ./gradlew :utils:clean && ./gradlew :utils:assembleRelease && ./gradlew :utils:publishMavenJavaPublicationToGitHubPackagesRepository
44+
* Run ./gradlew :library:clean && ./gradlew :library:assembleRelease && ./gradlew :library:publishMavenJavaPublicationToGitHubPackagesRepository
45+
*
46+
* Maven Central (via Sonatype Central Portal):
47+
* Run ./gradlew clean assembleRelease publishToSonatype closeAndReleaseSonatypeStagingRepository
48+
* Requires ossrhUsername and ossrhPassword in gradle.properties or OSSRH_USERNAME/OSSRH_PASSWORD env vars
6549
*/
6650

6751
afterEvaluate {
@@ -142,35 +126,8 @@ afterEvaluate {
142126
password = getGithubPackagesAccessToken()
143127
}
144128
}
145-
146-
maven {
147-
name = "MavenCentral"
148-
/** Configure path of your package repository on Github
149-
* Replace GITHUB_USERID with your or organisation Github userID and REPOSITORY with the repository name on GitHub
150-
* e.g. "https://maven.pkg.github.com/opensrp/opensrp-client-reporting"
151-
*/
152-
153-
def repositoryURL
154-
def timestampMsg = " at " + getDate()
155-
if (!version.contains("SNAPSHOT")) {
156-
println 'PROCESSING MAVEN RELEASE BUILD VERSION ' + project.VERSION_NAME + timestampMsg + '...'
157-
repositoryURL = hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
158-
: "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
159-
} else {
160-
println 'PROCESSING MAVEN REMOTE SNAPSHOT BUILD VERSION ' + project.VERSION_NAME + timestampMsg + '...'
161-
repositoryURL = hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
162-
: "https://s01.oss.sonatype.org/content/repositories/snapshots/"
163-
164-
}
165-
url = uri(repositoryURL)
166-
credentials {
167-
/** Create gradle.properties in root project folder file with
168-
* ossrhUsername=GITHUB_USER_ID & ossrhPassword=PERSONAL_ACCESS_TOKEN
169-
*/
170-
username = getOSSRHRepositoryUsername()
171-
password = getOSSRHRepositoryPassword()
172-
}
173-
}
129+
// Maven Central publishing is handled by the io.github.gradle-nexus.publish-plugin
130+
// configured in the root build.gradle. Run ./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository
174131
}
175132
}
176133

0 commit comments

Comments
 (0)