Skip to content

Commit 6aea0f4

Browse files
Merge branch '227-ci-read-packages' into 'dev'
GitLab: use OBX_READ_PACKAGES_TOKEN to read packages repo See merge request objectbox/objectbox-java!143
2 parents d0eae81 + fa57823 commit 6aea0f4

File tree

6 files changed

+69
-60
lines changed

6 files changed

+69
-60
lines changed

.gitlab-ci.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
image: objectboxio/buildenv-core:2023-07-28
44

55
# Assumes these environment variables are configured in GitLab CI/CD Settings:
6+
# - OBX_READ_PACKAGES_TOKEN
67
# - SONATYPE_USER
78
# - SONATYPE_PWD
89
# - GOOGLE_CHAT_WEBHOOK_JAVA_CI
@@ -18,8 +19,9 @@ variables:
1819
# Configure file.encoding to always use UTF-8 when running Gradle.
1920
# Use low priority processes to avoid Gradle builds consuming all build machine resources.
2021
GRADLE_OPTS: "-Dorg.gradle.daemon=false -Dfile.encoding=UTF-8 -Dorg.gradle.priority=low"
21-
GITLAB_REPO_ARGS: "-PgitlabUrl=$CI_SERVER_URL -PgitlabTokenName=Job-Token -PgitlabPrivateToken=$CI_JOB_TOKEN"
22-
CENTRAL_REPO_ARGS: "-PsonatypeUsername=$SONATYPE_USER -PsonatypePassword=$SONATYPE_PWD"
22+
GITLAB_REPO_ARGS: "-PgitlabUrl=$CI_SERVER_URL -PgitlabPrivateTokenName=Deploy-Token -PgitlabPrivateToken=$OBX_READ_PACKAGES_TOKEN"
23+
GITLAB_PUBLISH_ARGS: "-PgitlabPublishTokenName=Job-Token -PgitlabPublishToken=$CI_JOB_TOKEN"
24+
CENTRAL_PUBLISH_ARGS: "-PsonatypeUsername=$SONATYPE_USER -PsonatypePassword=$SONATYPE_PWD"
2325
# CI_COMMIT_REF_SLUG is the branch or tag name, but web-safe (only 0-9, a-z)
2426
VERSION_ARGS: "-PversionPostFix=$CI_COMMIT_REF_SLUG"
2527

@@ -127,7 +129,7 @@ upload-to-internal:
127129
- schedules # Do not upload artifacts from scheduled jobs to save on disk space
128130
- tags # Only upload artifacts from branches
129131
script:
130-
- ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS publishMavenJavaPublicationToGitLabRepository
132+
- ./gradlew $GITLAB_REPO_ARGS $GITLAB_PUBLISH_ARGS $VERSION_ARGS publishMavenJavaPublicationToGitLabRepository
131133

132134
upload-to-central:
133135
stage: upload-to-central
@@ -138,7 +140,7 @@ upload-to-central:
138140
- ci/send-to-gchat.sh "$GOOGLE_CHAT_WEBHOOK_JAVA_CI" --thread $CI_COMMIT_SHA "*Releasing Java library:* job $CI_JOB_NAME from branch $CI_COMMIT_BRANCH ($CI_COMMIT_SHORT_SHA)..."
139141
script:
140142
# Note: supply internal repo as tests use native dependencies that might not be published, yet.
141-
- ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS $CENTRAL_REPO_ARGS publishMavenJavaPublicationToSonatypeRepository closeAndReleaseSonatypeStagingRepository
143+
- ./gradlew $GITLAB_REPO_ARGS $VERSION_ARGS $CENTRAL_PUBLISH_ARGS publishMavenJavaPublicationToSonatypeRepository closeAndReleaseSonatypeStagingRepository
142144
after_script:
143145
# Also runs on failure, so show CI_JOB_STATUS.
144146
- ci/send-to-gchat.sh "$GOOGLE_CHAT_WEBHOOK_JAVA_CI" --thread $CI_COMMIT_SHA "*Releasing Java library:* *$CI_JOB_STATUS* for $CI_JOB_NAME"

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ configure<io.github.gradlenexus.publishplugin.NexusPublishExtension> {
9999
this.repositories {
100100
sonatype {
101101
if (project.hasProperty("sonatypeUsername") && project.hasProperty("sonatypePassword")) {
102-
println("nexusPublishing credentials supplied.")
103102
username.set(project.property("sonatypeUsername").toString())
104103
password.set(project.property("sonatypePassword").toString())
104+
println("Publishing: configured Maven Central repository")
105105
} else {
106-
println("nexusPublishing credentials NOT supplied.")
106+
println("Publishing: Maven Central repository not configured")
107107
}
108108
}
109109
}

buildSrc/src/main/kotlin/objectbox-publish.gradle.kts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
//
55
// To publish artifacts to the internal GitLab repo set:
66
// - gitlabUrl
7-
// - gitlabPrivateToken
8-
// - gitlabTokenName: optional, if set used instead of "Private-Token". Use for CI to specify e.g. "Job-Token".
7+
// - gitlabPublishToken: a token with permission to publish to the GitLab Package Repository
8+
// - gitlabPublishTokenName: optional, if set used instead of "Private-Token". Use for CI to specify e.g. "Job-Token".
99
//
1010
// To sign artifacts using an ASCII encoded PGP key given via a file set:
1111
// - signingKeyFile
@@ -28,21 +28,20 @@ publishing {
2828
repositories {
2929
maven {
3030
name = "GitLab"
31-
if (project.hasProperty("gitlabUrl") && project.hasProperty("gitlabPrivateToken")) {
31+
if (project.hasProperty("gitlabUrl") && project.hasProperty("gitlabPublishToken")) {
3232
// "https://gitlab.example.com/api/v4/projects/<PROJECT_ID>/packages/maven"
3333
val gitlabUrl = project.property("gitlabUrl")
3434
url = uri("$gitlabUrl/api/v4/projects/14/packages/maven")
35-
println("GitLab repository set to $url.")
36-
3735
credentials(HttpHeaderCredentials::class) {
38-
name = project.findProperty("gitlabTokenName")?.toString() ?: "Private-Token"
39-
value = project.property("gitlabPrivateToken").toString()
36+
name = project.findProperty("gitlabPublishTokenName")?.toString() ?: "Private-Token"
37+
value = project.property("gitlabPublishToken").toString()
4038
}
4139
authentication {
4240
create<HttpHeaderAuthentication>("header")
4341
}
42+
println("Publishing: configured GitLab repository $url")
4443
} else {
45-
println("WARNING: Can not publish to GitLab: gitlabUrl or gitlabPrivateToken not set.")
44+
println("Publishing: GitLab repository not configured")
4645
}
4746
}
4847
// Note: Sonatype repo created by publish-plugin, see root build.gradle.kts.
@@ -96,8 +95,9 @@ signing {
9695
project.property("signingPassword").toString()
9796
)
9897
sign(publishing.publications["mavenJava"])
98+
println("Publishing: configured signing with key file")
9999
} else {
100-
println("Signing information missing/incomplete for ${project.name}")
100+
println("Publishing: signing not configured")
101101
}
102102
}
103103

tests/objectbox-java-test/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ repositories {
2525
// Native lib might be deployed only in internal repo
2626
if (project.hasProperty("gitlabUrl")) {
2727
val gitlabUrl = project.property("gitlabUrl")
28-
println("gitlabUrl=$gitlabUrl added to repositories.")
2928
maven {
3029
url = uri("$gitlabUrl/api/v4/groups/objectbox/-/packages/maven")
3130
name = "GitLab"
3231
credentials(HttpHeaderCredentials::class) {
33-
name = project.findProperty("gitlabTokenName")?.toString() ?: "Private-Token"
32+
name = project.findProperty("gitlabPrivateTokenName")?.toString() ?: "Private-Token"
3433
value = project.property("gitlabPrivateToken").toString()
3534
}
3635
authentication {
3736
create<HttpHeaderAuthentication>("header")
3837
}
38+
println("Dependencies: added GitLab repository $url")
3939
}
4040
} else {
41-
println("Property gitlabUrl not set.")
41+
println("Dependencies: GitLab repository not added. To resolve dependencies from the GitLab Package Repository, set gitlabUrl and gitlabPrivateToken.")
4242
}
4343
}
4444

tests/test-proguard/build.gradle

Lines changed: 0 additions & 42 deletions
This file was deleted.

tests/test-proguard/build.gradle.kts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
plugins {
2+
id("java-library")
3+
}
4+
5+
tasks.withType<JavaCompile> {
6+
// Note: use release flag instead of sourceCompatibility and targetCompatibility to ensure only JDK 8 API is used.
7+
// https://docs.gradle.org/current/userguide/building_java_projects.html#sec:java_cross_compilation
8+
options.release.set(8)
9+
}
10+
11+
repositories {
12+
// Native lib might be deployed only in internal repo
13+
if (project.hasProperty("gitlabUrl")) {
14+
val gitlabUrl = project.property("gitlabUrl")
15+
maven {
16+
url = uri("$gitlabUrl/api/v4/groups/objectbox/-/packages/maven")
17+
name = "GitLab"
18+
credentials(HttpHeaderCredentials::class) {
19+
name = project.findProperty("gitlabPrivateTokenName")?.toString() ?: "Private-Token"
20+
value = project.property("gitlabPrivateToken").toString()
21+
}
22+
authentication {
23+
create<HttpHeaderAuthentication>("header")
24+
}
25+
println("Dependencies: added GitLab repository $url")
26+
}
27+
} else {
28+
println("Dependencies: GitLab repository not added. To resolve dependencies from the GitLab Package Repository, set gitlabUrl and gitlabPrivateToken.")
29+
}
30+
}
31+
32+
val obxJniLibVersion: String by rootProject.extra
33+
34+
val junitVersion: String by rootProject.extra
35+
36+
dependencies {
37+
implementation(project(":objectbox-java"))
38+
39+
// Check flag to use locally compiled version to avoid dependency cycles
40+
if (!project.hasProperty("noObjectBoxTestDepencies")
41+
|| project.property("noObjectBoxTestDepencies") == false) {
42+
println("Using $obxJniLibVersion")
43+
implementation(obxJniLibVersion)
44+
} else {
45+
println("Did NOT add native dependency")
46+
}
47+
48+
testImplementation("junit:junit:$junitVersion")
49+
}

0 commit comments

Comments
 (0)