Skip to content

Commit 2a639fe

Browse files
Publish: use maven-publish plugin, publish to GitLab.
1 parent 761de8d commit 2a639fe

File tree

7 files changed

+119
-197
lines changed

7 files changed

+119
-197
lines changed

Jenkinsfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ String versionPostfix = isPublish ? '' : BRANCH_NAME // Build script detects emp
1010
def internalRepoArgs = '-PinternalObjectBoxRepo=$MVN_REPO_URL ' +
1111
'-PinternalObjectBoxRepoUser=$MVN_REPO_LOGIN_USR ' +
1212
'-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 '
13+
def gitlabRepoArgs = '-PgitlabUrl=$GITLAB_URL -PgitlabPrivateToken=$GITLAB_TOKEN'
1614
def uploadRepoArgsCentral = '-PsonatypeUsername=$OSSRH_LOGIN_USR -PsonatypePassword=$OSSRH_LOGIN_PSW'
1715

1816
// https://jenkins.io/doc/book/pipeline/syntax/
@@ -22,7 +20,8 @@ pipeline {
2220
environment {
2321
MVN_REPO_LOGIN = credentials('objectbox_internal_mvn_user')
2422
MVN_REPO_URL = credentials('objectbox_internal_mvn_repo_http')
25-
MVN_REPO_UPLOAD_URL = credentials('objectbox_internal_mvn_repo')
23+
GITLAB_URL = credentials('gitlab_url')
24+
GITLAB_TOKEN = credentials('GITLAB_TOKEN_ALL')
2625
// Note: for key use Jenkins secret file with PGP key as text in ASCII-armored format.
2726
ORG_GRADLE_PROJECT_signingKeyFile = credentials('objectbox_signing_key')
2827
ORG_GRADLE_PROJECT_signingKeyId = credentials('objectbox_signing_key_id')
@@ -66,7 +65,7 @@ pipeline {
6665

6766
stage('upload-to-internal') {
6867
steps {
69-
sh "./gradlew $gradleArgs $internalRepoArgs $uploadRepoArgs -PversionPostFix=$versionPostfix uploadArchives"
68+
sh "./gradlew $gradleArgs $internalRepoArgs $gitlabRepoArgs -PversionPostFix=$versionPostfix publishMavenJavaPublicationToGitLabRepository"
7069
}
7170
}
7271

@@ -81,7 +80,7 @@ pipeline {
8180

8281
// Step 1: upload files to staging repository.
8382
// Note: supply internal repo as tests use native dependencies that might not be published, yet.
84-
sh "./gradlew $gradleArgs $internalRepoArgs $uploadRepoArgsCentral uploadArchives"
83+
sh "./gradlew $gradleArgs $internalRepoArgs $uploadRepoArgsCentral publishMavenJavaPublicationToSonatypeRepository"
8584

8685
// Step 2: close and release staging repository.
8786
sh "./gradlew $gradleArgs $uploadRepoArgsCentral closeAndReleaseRepository"

build.gradle

Lines changed: 67 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,9 @@ def hasSigningProperties() {
8383
}
8484

8585
configure(subprojects.findAll { projectNamesToPublish.contains(it.name) }) {
86-
apply plugin: 'maven'
86+
apply plugin: 'maven-publish'
8787
apply plugin: 'signing'
8888

89-
configurations {
90-
deployerJars
91-
}
92-
93-
dependencies {
94-
// Using an older version to remain compatible with Wagon API used by Gradle/Maven
95-
deployerJars 'org.apache.maven.wagon:wagon-webdav-jackrabbit:3.2.0'
96-
deployerJars 'org.apache.maven.wagon:wagon-ftp:3.3.2'
97-
}
98-
9989
signing {
10090
if (hasSigningProperties()) {
10191
String signingKey = new File(signingKeyFile).text
@@ -106,79 +96,78 @@ configure(subprojects.findAll { projectNamesToPublish.contains(it.name) }) {
10696
}
10797
}
10898

109-
// Use afterEvaluate or all dependencies will be lost in the generated POM
110-
afterEvaluate {
111-
uploadArchives {
112-
repositories {
113-
mavenDeployer {
114-
def preferredRepo = project.findProperty('preferredRepo')
115-
println "preferredRepo=$preferredRepo"
116-
117-
if (preferredRepo == 'local') {
118-
repository url: repositories.mavenLocal().url
119-
println "uploadArchives repo is mavenLocal()."
120-
} else if (preferredRepo != null
121-
&& project.hasProperty('preferredUsername')
122-
&& project.hasProperty('preferredPassword')) {
123-
if (!hasSigningProperties()) {
124-
throw new InvalidUserDataException("To upload to repo signing is required.")
125-
}
126-
127-
configuration = configurations.deployerJars
128-
129-
// replace placeholders
130-
def repositoryUrl = preferredRepo
131-
.replace('__groupId__', project.group)
132-
.replace('__artifactId__', project.archivesBaseName)
133-
repository(url: repositoryUrl) {
134-
authentication(userName: preferredUsername, password: preferredPassword)
135-
}
136-
137-
println "uploadArchives repo is $repositoryUrl."
138-
} else if (project.hasProperty('sonatypeUsername')
139-
&& project.hasProperty('sonatypePassword')) {
140-
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
141-
142-
def isSnapshot = version.endsWith('-SNAPSHOT')
143-
def sonatypeRepositoryUrl = isSnapshot
144-
? "https://oss.sonatype.org/content/repositories/snapshots/"
145-
: "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
146-
repository(url: sonatypeRepositoryUrl) {
147-
authentication(userName: sonatypeUsername, password: sonatypePassword)
148-
}
149-
150-
println "uploadArchives repo is $sonatypeRepositoryUrl."
151-
} else {
152-
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
111+
}
112+
authentication {
113+
header(HttpHeaderAuthentication)
114+
}
115+
} else {
116+
println "WARNING: Can not publish to GitLab: gitlabUrl or gitlabPrivateToken not set."
117+
}
118+
}
119+
maven {
120+
name = 'Sonatype'
121+
url = version.endsWith('SNAPSHOT') ?
122+
"https://oss.sonatype.org/content/repositories/snapshots/" :
123+
"https://oss.sonatype.org/service/local/staging/deploy/maven2/"
124+
if (project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword')) {
125+
if (!hasSigningProperties()) {
126+
throw new InvalidUserDataException("To upload to repo signing is required.")
153127
}
154128

155-
pom.project {
156-
packaging 'jar'
157-
url 'https://objectbox.io'
158-
159-
scm {
160-
url 'https://github.com/objectbox/objectbox-java'
161-
connection 'scm:git@github.com:objectbox/objectbox-java.git'
162-
developerConnection 'scm:git@github.com:objectbox/objectbox-java.git'
163-
}
164-
165-
developers {
166-
developer {
167-
id 'ObjectBox'
168-
name 'ObjectBox'
169-
}
170-
}
129+
credentials {
130+
username = sonatypeUsername
131+
password = sonatypePassword
132+
}
133+
} else {
134+
println "WARNING: Can not publish to Sonatype OSSRH: sonatypeUsername or sonatypePassword not set."
135+
}
136+
}
137+
}
171138

172-
issueManagement {
173-
system 'GitHub Issues'
174-
url 'https://github.com/objectbox/objectbox-java/issues'
139+
publications {
140+
mavenJava(MavenPublication) {
141+
// Note: Projects set additional specific properties.
142+
pom {
143+
packaging = 'jar'
144+
url = 'https://objectbox.io'
145+
licenses {
146+
license {
147+
name = 'The Apache Software License, Version 2.0'
148+
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
149+
distribution = 'repo'
175150
}
176-
177-
organization {
178-
name 'ObjectBox Ltd.'
179-
url 'https://objectbox.io'
151+
}
152+
developers {
153+
developer {
154+
id = 'ObjectBox'
155+
name = 'ObjectBox'
180156
}
181157
}
158+
issueManagement {
159+
system = 'GitHub Issues'
160+
url = 'https://github.com/objectbox/objectbox-java/issues'
161+
}
162+
organization {
163+
name = 'ObjectBox Ltd.'
164+
url = 'https://objectbox.io'
165+
}
166+
scm {
167+
connection = 'scm:git@github.com:objectbox/objectbox-java.git'
168+
developerConnection = 'scm:git@github.com:objectbox/objectbox-java.git'
169+
url = 'https://github.com/objectbox/objectbox-java'
170+
}
182171
}
183172
}
184173
}

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
}

objectbox-kotlin/build.gradle

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,21 @@ task sourcesJar(type: Jar) {
4545
from sourceSets.main.allSource
4646
}
4747

48-
artifacts {
49-
// java plugin adds jar.
50-
archives javadocJar
51-
archives sourcesJar
52-
}
53-
5448
dependencies {
5549
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
5650

5751
api project(':objectbox-java')
5852
}
5953

60-
61-
uploadArchives {
62-
repositories {
63-
mavenDeployer {
64-
// Basic definitions are defined in root project
65-
pom.project {
66-
name 'ObjectBox Kotlin'
67-
description 'ObjectBox is a fast NoSQL database for Objects'
68-
69-
licenses {
70-
license {
71-
name 'The Apache Software License, Version 2.0'
72-
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
73-
distribution 'repo'
74-
}
75-
}
76-
}
54+
// Set project-specific properties.
55+
publishing.publications {
56+
mavenJava(MavenPublication) {
57+
from components.java
58+
artifact sourcesJar
59+
artifact javadocJar
60+
pom {
61+
name = 'ObjectBox Kotlin'
62+
description = 'ObjectBox is a fast NoSQL database for Objects'
7763
}
7864
}
79-
}
65+
}

objectbox-rxjava/build.gradle

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,15 @@ task sourcesJar(type: Jar) {
2121
from sourceSets.main.allSource
2222
}
2323

24-
artifacts {
25-
// java plugin adds jar.
26-
archives javadocJar
27-
archives sourcesJar
28-
}
29-
30-
uploadArchives {
31-
repositories {
32-
mavenDeployer {
33-
// Basic definitions are defined in root project
34-
pom.project {
35-
name 'ObjectBox RxJava API'
36-
description 'RxJava extension for ObjectBox'
37-
38-
licenses {
39-
license {
40-
name 'The Apache Software License, Version 2.0'
41-
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
42-
distribution 'repo'
43-
}
44-
}
45-
}
24+
// Set project-specific properties.
25+
publishing.publications {
26+
mavenJava(MavenPublication) {
27+
from components.java
28+
artifact sourcesJar
29+
artifact javadocJar
30+
pom {
31+
name = 'ObjectBox RxJava API'
32+
description = 'RxJava extension for ObjectBox'
4633
}
4734
}
4835
}

0 commit comments

Comments
 (0)