Skip to content

Commit 12558e9

Browse files
Merge branch '641-publish-to-central' into dev
2 parents 78e6133 + 3f4f605 commit 12558e9

File tree

10 files changed

+155
-235
lines changed

10 files changed

+155
-235
lines changed

Jenkinsfile

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,16 @@ boolean isPublish = BRANCH_NAME == 'publish'
77
String versionPostfix = isPublish ? '' : BRANCH_NAME // Build script detects empty string as not set.
88

99
// Note: using single quotes to avoid Groovy String interpolation leaking secrets.
10-
def internalRepoArgs = '-PinternalObjectBoxRepo=$MVN_REPO_URL ' +
11-
'-PinternalObjectBoxRepoUser=$MVN_REPO_LOGIN_USR ' +
12-
'-PinternalObjectBoxRepoPassword=$MVN_REPO_LOGIN_PSW'
13-
def uploadRepoArgs = '-PpreferredRepo=$MVN_REPO_UPLOAD_URL ' +
14-
'-PpreferredUsername=$MVN_REPO_LOGIN_USR ' +
15-
'-PpreferredPassword=$MVN_REPO_LOGIN_PSW '
16-
// Note: add quotes around URL parameter to avoid line breaks due to semicolon in URL.
17-
def uploadRepoArgsBintray = '\"-PpreferredRepo=$BINTRAY_URL\" ' +
18-
'-PpreferredUsername=$BINTRAY_LOGIN_USR ' +
19-
'-PpreferredPassword=$BINTRAY_LOGIN_PSW'
10+
def gitlabRepoArgs = '-PgitlabUrl=$GITLAB_URL -PgitlabPrivateToken=$GITLAB_TOKEN'
11+
def uploadRepoArgsCentral = '-PsonatypeUsername=$OSSRH_LOGIN_USR -PsonatypePassword=$OSSRH_LOGIN_PSW'
2012

2113
// https://jenkins.io/doc/book/pipeline/syntax/
2214
pipeline {
2315
agent { label 'java' }
2416

2517
environment {
26-
MVN_REPO_LOGIN = credentials('objectbox_internal_mvn_user')
27-
MVN_REPO_URL = credentials('objectbox_internal_mvn_repo_http')
28-
MVN_REPO_UPLOAD_URL = credentials('objectbox_internal_mvn_repo')
18+
GITLAB_URL = credentials('gitlab_url')
19+
GITLAB_TOKEN = credentials('GITLAB_TOKEN_ALL')
2920
// Note: for key use Jenkins secret file with PGP key as text in ASCII-armored format.
3021
ORG_GRADLE_PROJECT_signingKeyFile = credentials('objectbox_signing_key')
3122
ORG_GRADLE_PROJECT_signingKeyId = credentials('objectbox_signing_key_id')
@@ -58,7 +49,7 @@ pipeline {
5849

5950
stage('build-java') {
6051
steps {
61-
sh "./ci/test-with-asan.sh $gradleArgs $internalRepoArgs -Dextensive-tests=true clean test " +
52+
sh "./ci/test-with-asan.sh $gradleArgs $gitlabRepoArgs -Dextensive-tests=true clean test " +
6253
"--tests io.objectbox.FunctionalTestSuite " +
6354
"--tests io.objectbox.test.proguard.ObfuscatedEntityTest " +
6455
"--tests io.objectbox.rx.QueryObserverTest " +
@@ -69,25 +60,24 @@ pipeline {
6960

7061
stage('upload-to-internal') {
7162
steps {
72-
sh "./gradlew $gradleArgs $internalRepoArgs $uploadRepoArgs -PversionPostFix=$versionPostfix uploadArchives"
63+
sh "./gradlew $gradleArgs $gitlabRepoArgs -PversionPostFix=$versionPostfix publishMavenJavaPublicationToGitLabRepository"
7364
}
7465
}
7566

76-
stage('upload-to-bintray') {
67+
stage('upload-to-central') {
7768
when { expression { return isPublish } }
7869
environment {
79-
BINTRAY_URL = credentials('bintray_url')
80-
BINTRAY_LOGIN = credentials('bintray_login')
70+
OSSRH_LOGIN = credentials('ossrh-login')
8171
}
8272
steps {
8373
googlechatnotification url: 'id:gchat_java',
84-
message: "*Publishing* ${currentBuild.fullDisplayName} to Bintray...\n${env.BUILD_URL}"
74+
message: "*Publishing* ${currentBuild.fullDisplayName} to Central...\n${env.BUILD_URL}"
8575

8676
// Note: supply internal repo as tests use native dependencies that might not be published, yet.
87-
sh "./gradlew $gradleArgs $internalRepoArgs $uploadRepoArgsBintray uploadArchives"
77+
sh "./gradlew $gradleArgs $gitlabRepoArgs $uploadRepoArgsCentral publishMavenJavaPublicationToSonatypeRepository closeAndReleaseStagingRepository"
8878

8979
googlechatnotification url: 'id:gchat_java',
90-
message: "Published ${currentBuild.fullDisplayName} successfully to Bintray - check https://bintray.com/objectbox/objectbox\n${env.BUILD_URL}"
80+
message: "Published ${currentBuild.fullDisplayName} successfully to Central - check https://repo1.maven.org/maven2/io/objectbox/ in a few minutes.\n${env.BUILD_URL}"
9181
}
9282
}
9383

build.gradle

Lines changed: 69 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ buildscript {
4242
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
4343
// https://github.com/spotbugs/spotbugs-gradle-plugin/releases
4444
classpath "gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.5.1"
45+
classpath "io.github.gradle-nexus:publish-plugin:1.0.0"
4546
}
4647
}
4748

@@ -82,19 +83,9 @@ def hasSigningProperties() {
8283
}
8384

8485
configure(subprojects.findAll { projectNamesToPublish.contains(it.name) }) {
85-
apply plugin: 'maven'
86+
apply plugin: 'maven-publish'
8687
apply plugin: 'signing'
8788

88-
configurations {
89-
deployerJars
90-
}
91-
92-
dependencies {
93-
// Using an older version to remain compatible with Wagon API used by Gradle/Maven
94-
deployerJars 'org.apache.maven.wagon:wagon-webdav-jackrabbit:3.2.0'
95-
deployerJars 'org.apache.maven.wagon:wagon-ftp:3.3.2'
96-
}
97-
9889
signing {
9990
if (hasSigningProperties()) {
10091
String signingKey = new File(signingKeyFile).text
@@ -105,79 +96,61 @@ configure(subprojects.findAll { projectNamesToPublish.contains(it.name) }) {
10596
}
10697
}
10798

108-
// Use afterEvaluate or all dependencies will be lost in the generated POM
109-
afterEvaluate {
110-
uploadArchives {
111-
repositories {
112-
mavenDeployer {
113-
def preferredRepo = project.findProperty('preferredRepo')
114-
println "preferredRepo=$preferredRepo"
115-
116-
if (preferredRepo == 'local') {
117-
repository url: repositories.mavenLocal().url
118-
println "uploadArchives repo is mavenLocal()."
119-
} else if (preferredRepo != null
120-
&& project.hasProperty('preferredUsername')
121-
&& project.hasProperty('preferredPassword')) {
122-
if (!hasSigningProperties()) {
123-
throw new InvalidUserDataException("To upload to repo signing is required.")
124-
}
125-
126-
configuration = configurations.deployerJars
127-
128-
// replace placeholders
129-
def repositoryUrl = preferredRepo
130-
.replace('__groupId__', project.group)
131-
.replace('__artifactId__', project.archivesBaseName)
132-
repository(url: repositoryUrl) {
133-
authentication(userName: preferredUsername, password: preferredPassword)
134-
}
135-
136-
println "uploadArchives repo is $repositoryUrl."
137-
} else if (project.hasProperty('sonatypeUsername')
138-
&& project.hasProperty('sonatypePassword')) {
139-
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
140-
141-
def isSnapshot = version.endsWith('-SNAPSHOT')
142-
def sonatypeRepositoryUrl = isSnapshot
143-
? "https://oss.sonatype.org/content/repositories/snapshots/"
144-
: "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
145-
repository(url: sonatypeRepositoryUrl) {
146-
authentication(userName: sonatypeUsername, password: sonatypePassword)
147-
}
148-
149-
println "uploadArchives repo is $sonatypeRepositoryUrl."
150-
} else {
151-
println "WARNING: uploadArchives settings incomplete, can not upload archives."
99+
publishing {
100+
repositories {
101+
maven {
102+
name = 'GitLab'
103+
if (project.hasProperty('gitlabUrl') && project.hasProperty('gitlabPrivateToken')) {
104+
// "https://gitlab.example.com/api/v4/projects/<PROJECT_ID>/packages/maven"
105+
url = "$gitlabUrl/api/v4/projects/14/packages/maven"
106+
println "GitLab repository set to $url."
107+
108+
credentials(HttpHeaderCredentials) {
109+
name = "Private-Token"
110+
value = gitlabPrivateToken
152111
}
112+
authentication {
113+
header(HttpHeaderAuthentication)
114+
}
115+
} else {
116+
println "WARNING: Can not publish to GitLab: gitlabUrl or gitlabPrivateToken not set."
117+
}
118+
}
119+
// Note: Sonatype repo created by publish-plugin.
120+
}
153121

154-
pom.project {
155-
packaging 'jar'
156-
url 'https://objectbox.io'
157-
158-
scm {
159-
url 'https://github.com/objectbox/objectbox-java'
160-
connection 'scm:git@github.com:objectbox/objectbox-java.git'
161-
developerConnection 'scm:git@github.com:objectbox/objectbox-java.git'
162-
}
163-
164-
developers {
165-
developer {
166-
id 'ObjectBox'
167-
name 'ObjectBox'
168-
}
169-
}
170-
171-
issueManagement {
172-
system 'GitHub Issues'
173-
url 'https://github.com/objectbox/objectbox-java/issues'
122+
publications {
123+
mavenJava(MavenPublication) {
124+
// Note: Projects set additional specific properties.
125+
pom {
126+
packaging = 'jar'
127+
url = 'https://objectbox.io'
128+
licenses {
129+
license {
130+
name = 'The Apache Software License, Version 2.0'
131+
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
132+
distribution = 'repo'
174133
}
175-
176-
organization {
177-
name 'ObjectBox Ltd.'
178-
url 'https://objectbox.io'
134+
}
135+
developers {
136+
developer {
137+
id = 'ObjectBox'
138+
name = 'ObjectBox'
179139
}
180140
}
141+
issueManagement {
142+
system = 'GitHub Issues'
143+
url = 'https://github.com/objectbox/objectbox-java/issues'
144+
}
145+
organization {
146+
name = 'ObjectBox Ltd.'
147+
url = 'https://objectbox.io'
148+
}
149+
scm {
150+
connection = 'scm:git@github.com:objectbox/objectbox-java.git'
151+
developerConnection = 'scm:git@github.com:objectbox/objectbox-java.git'
152+
url = 'https://github.com/objectbox/objectbox-java'
153+
}
181154
}
182155
}
183156
}
@@ -187,3 +160,20 @@ configure(subprojects.findAll { projectNamesToPublish.contains(it.name) }) {
187160
wrapper {
188161
distributionType = Wrapper.DistributionType.ALL
189162
}
163+
164+
// Plugin to publish to Central https://github.com/gradle-nexus/publish-plugin/
165+
// This plugin ensures a separate, named staging repo is created for each build when publishing.
166+
apply plugin: "io.github.gradle-nexus.publish-plugin"
167+
nexusPublishing {
168+
repositories {
169+
sonatype {
170+
if (project.hasProperty("sonatypeUsername") && project.hasProperty("sonatypePassword")) {
171+
println('nexusPublishing credentials supplied.')
172+
username = sonatypeUsername
173+
password = sonatypePassword
174+
} else {
175+
println('nexusPublishing credentials NOT supplied.')
176+
}
177+
}
178+
}
179+
}

ci/Jenkinsfile-Windows

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ String gradleArgs = '-Dorg.gradle.daemon=false --stacktrace'
66
boolean isPublish = BRANCH_NAME == 'publish'
77

88
// Note: using single quotes to avoid Groovy String interpolation leaking secrets.
9-
def internalRepoArgsBat = '-PinternalObjectBoxRepo=%MVN_REPO_URL% ' +
10-
'-PinternalObjectBoxRepoUser=%MVN_REPO_LOGIN_USR% ' +
11-
'-PinternalObjectBoxRepoPassword=%MVN_REPO_LOGIN_PSW%'
9+
def gitlabRepoArgsBat = '-PgitlabUrl=%GITLAB_URL% -PgitlabPrivateToken=%GITLAB_TOKEN%'
1210

1311
// https://jenkins.io/doc/book/pipeline/syntax/
1412
pipeline {
1513
agent { label 'windows' }
1614

1715
environment {
18-
MVN_REPO_URL = credentials('objectbox_internal_mvn_repo_http')
19-
MVN_REPO_LOGIN = credentials('objectbox_internal_mvn_user')
16+
GITLAB_URL = credentials('gitlab_url')
17+
GITLAB_TOKEN = credentials('GITLAB_TOKEN_ALL')
2018
}
2119

2220
options {
@@ -41,7 +39,7 @@ pipeline {
4139
// Remove files to avoid archiving them again.
4240
bat 'del /q /s hs_err_pid*.log'
4341

44-
bat "gradlew $gradleArgs $internalRepoArgsBat cleanTest build test"
42+
bat "gradlew $gradleArgs $gitlabRepoArgsBat cleanTest build test"
4543
}
4644
post {
4745
always {
@@ -60,7 +58,7 @@ pipeline {
6058
// 32-bit ObjectBox to run tests (see build.gradle file).
6159
// Note: assumes JAVA_HOME_X86 is set to 32-bit JDK path.
6260
// Note: no space before && or value has space as well.
63-
bat "set TEST_WITH_JAVA_X86=true&& gradlew $gradleArgs $internalRepoArgsBat cleanTest build test"
61+
bat "set TEST_WITH_JAVA_X86=true&& gradlew $gradleArgs $gitlabRepoArgsBat cleanTest build test"
6462
}
6563
post {
6664
always {
@@ -73,7 +71,7 @@ pipeline {
7371
stage('package-javadoc-for-web') {
7472
when { expression { return isPublish } }
7573
steps {
76-
bat "gradlew $gradleArgs $internalRepoArgsBat :objectbox-java:packageJavadocForWeb"
74+
bat "gradlew $gradleArgs $gitlabRepoArgsBat :objectbox-java:packageJavadocForWeb"
7775
}
7876
post {
7977
always {

objectbox-java-api/build.gradle

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,15 @@ task sourcesJar(type: Jar) {
1313
archiveClassifier.set('sources')
1414
}
1515

16-
artifacts {
17-
// java plugin adds jar.
18-
archives javadocJar
19-
archives sourcesJar
20-
}
21-
22-
uploadArchives {
23-
repositories {
24-
mavenDeployer {
25-
// Basic definitions are defined in root project
26-
pom.project {
27-
name 'ObjectBox API'
28-
description 'ObjectBox is a fast NoSQL database for Objects'
29-
30-
licenses {
31-
license {
32-
name 'The Apache Software License, Version 2.0'
33-
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
34-
distribution 'repo'
35-
}
36-
}
37-
}
16+
// Set project-specific properties.
17+
publishing.publications {
18+
mavenJava(MavenPublication) {
19+
from components.java
20+
artifact sourcesJar
21+
artifact javadocJar
22+
pom {
23+
name = 'ObjectBox API'
24+
description = 'ObjectBox is a fast NoSQL database for Objects'
3825
}
3926
}
40-
}
27+
}

objectbox-java/build.gradle

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -125,28 +125,15 @@ task sourcesJar(type: Jar) {
125125
archiveClassifier.set('sources')
126126
}
127127

128-
artifacts {
129-
// java plugin adds jar.
130-
archives javadocJar
131-
archives sourcesJar
132-
}
133-
134-
uploadArchives {
135-
repositories {
136-
mavenDeployer {
137-
// Basic definitions are defined in root project
138-
pom.project {
139-
name 'ObjectBox Java (only)'
140-
description 'ObjectBox is a fast NoSQL database for Objects'
141-
142-
licenses {
143-
license {
144-
name 'The Apache Software License, Version 2.0'
145-
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
146-
distribution 'repo'
147-
}
148-
}
149-
}
128+
// Set project-specific properties.
129+
publishing.publications {
130+
mavenJava(MavenPublication) {
131+
from components.java
132+
artifact sourcesJar
133+
artifact javadocJar
134+
pom {
135+
name = 'ObjectBox Java (only)'
136+
description = 'ObjectBox is a fast NoSQL database for Objects'
150137
}
151138
}
152139
}

0 commit comments

Comments
 (0)