Skip to content

Commit a44734e

Browse files
committed
Fix publishing scripts.
1 parent 515ead3 commit a44734e

File tree

2 files changed

+115
-45
lines changed

2 files changed

+115
-45
lines changed

gradle/publishing_aar.gradle

Lines changed: 64 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,86 @@
11
apply plugin: 'maven-publish'
22
apply plugin: 'signing'
3-
apply from: "$rootDir/gradle/sonatype-central.gradle"
43

5-
java {
6-
withSourcesJar()
7-
withJavadocJar()
4+
android {
5+
// Explicitly set the NDK release to ensure we use the latest stable, as
6+
// opposed to the default NDK tied to the AGP version.
7+
ndkVersion = '28.1.13356709'
8+
defaultConfig {
9+
ndk {
10+
// Explicitly enable the 'riscv64' ABI with 'abiFilters' as it is
11+
// not part of the default ABI set today.
12+
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64', 'riscv64'
13+
}
14+
}
15+
publishing {
16+
singleVariant("release") {
17+
withSourcesJar()
18+
withJavadocJar()
19+
}
20+
}
821
}
922

1023
// Task to publish to local repository for bundle creation
1124
tasks.register("publishToLocalMaven", Task) {
1225
dependsOn "publishMavenPublicationToLocalRepository"
1326
}
1427

15-
publishing {
16-
publications {
17-
maven(MavenPublication) {
18-
from components.java
1928

20-
pom {
21-
name = 'Dexmaker'
22-
description = project.description
23-
url = 'https://github.com/linkedin/dexmaker'
24-
licenses {
25-
license {
26-
name = 'The Apache Software License, Version 2.0'
27-
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
29+
// AGP creates the components in afterEvaluate, so we need to use it too
30+
// https://developer.android.com/studio/build/maven-publish-plugin
31+
afterEvaluate {
32+
apply from: "$rootDir/gradle/sonatype-central.gradle"
33+
34+
publishing {
35+
publications {
36+
maven(MavenPublication) {
37+
from components.release
38+
39+
pom {
40+
name = 'Dexmaker'
41+
description = project.description
42+
url = 'https://github.com/linkedin/dexmaker'
43+
licenses {
44+
license {
45+
name = 'The Apache Software License, Version 2.0'
46+
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
47+
}
2848
}
29-
}
30-
developers {
31-
developer {
32-
id = 'com.linkedin'
33-
name = 'LinkedIn Corp'
49+
developers {
50+
developer {
51+
id = 'com.linkedin'
52+
name = 'LinkedIn Corp'
53+
}
54+
}
55+
scm {
56+
connection = 'scm:git:git://github.com/linkedin/dexmaker.git'
57+
developerConnection = 'scm:git:ssh://github.com:linkedin/dexmaker.git'
58+
url = 'https://github.com/linkedin/dexmaker/tree/main'
3459
}
3560
}
36-
scm {
37-
connection = 'scm:git:git://github.com/linkedin/dexmaker.git'
38-
developerConnection = 'scm:git:ssh://github.com:linkedin/dexmaker.git'
39-
url = 'https://github.com/linkedin/dexmaker/tree/main'
40-
}
41-
}
4261

43-
repositories {
44-
def sonatypeUsername = System.getenv("SONATYPE_USER")
45-
def sonatypePassword = System.getenv("SONATYPE_PASSWORD")
62+
repositories {
63+
def sonatypeUsername = System.getenv("SONATYPE_USER")
64+
def sonatypePassword = System.getenv("SONATYPE_PASSWORD")
4665

47-
// Local Maven repository for local development
48-
mavenLocal()
66+
// Local Maven repository for local development
67+
mavenLocal()
4968

50-
// Note: Sonatype Central Portal snapshots are published via API, not Maven repository
51-
// The publishSnapshotToCentral task handles the API-based upload
69+
// Note: Sonatype Central Portal snapshots are published via API, not Maven repository
70+
// The publishSnapshotToCentral task handles the API-based upload
71+
}
5272
}
5373
}
5474
}
55-
}
5675

57-
// DEXMAKER_GPG_PRIVATE_KEY should contain the armoured private key that
58-
// starts with -----BEGIN PGP PRIVATE KEY BLOCK-----
59-
// It can be obtained with gpg --armour --export-secret-keys KEY_ID
60-
def signingKey = System.getenv("DEXMAKER_GPG_PRIVATE_KEY")
61-
def signingPassword = System.getenv("DEXMAKER_GPG_PRIVATE_KEY_PASSWORD")
62-
signing {
63-
required { signingKey != null && signingPassword != null }
64-
useInMemoryPgpKeys(signingKey, signingPassword)
65-
sign publishing.publications.maven
76+
// DEXMAKER_GPG_PRIVATE_KEY should contain the armoured private key that
77+
// starts with -----BEGIN PGP PRIVATE KEY BLOCK-----
78+
// It can be obtained with gpg --armour --export-secret-keys KEY_ID
79+
def signingKey = System.getenv("DEXMAKER_GPG_PRIVATE_KEY")
80+
def signingPassword = System.getenv("DEXMAKER_GPG_PRIVATE_KEY_PASSWORD")
81+
signing {
82+
required { signingKey != null && signingPassword != null }
83+
useInMemoryPgpKeys(signingKey, signingPassword)
84+
sign publishing.publications.maven
85+
}
6686
}

gradle/sonatype-central.gradle

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,57 @@ tasks.register("publishSnapshotToCentral") {
8282
}
8383
}
8484

85-
dependsOn "publishAllPublicationsToCentralSnapshotRepository"
85+
dependsOn publishToLocalMaven
86+
87+
doLast {
88+
def sonatypeUsername = System.getenv("SONATYPE_USER")
89+
def sonatypePassword = System.getenv("SONATYPE_PASSWORD")
90+
91+
if (!sonatypeUsername || !sonatypePassword) {
92+
throw new GradleException("SONATYPE_USER and SONATYPE_PASSWORD environment variables must be set")
93+
}
94+
95+
// Create base64 encoded credentials for Basic Auth
96+
def credentials = "${sonatypeUsername}:${sonatypePassword}"
97+
def encodedCredentials = Base64.getEncoder().encodeToString(credentials.getBytes())
98+
99+
// Find all artifacts in the local repository
100+
def repoDir = new File(project.buildDir, "repo")
101+
def groupPath = project.group.toString().replace('.', '/')
102+
def artifactDir = new File(repoDir, "${groupPath}/${project.name}/${project.version}")
103+
104+
if (!artifactDir.exists()) {
105+
throw new GradleException("No artifacts found in ${artifactDir}. Run publishToLocalMaven first.")
106+
}
107+
108+
// Upload each artifact file
109+
artifactDir.eachFile { file ->
110+
if (file.isFile() && !file.name.endsWith('.sha1') && !file.name.endsWith('.md5')) {
111+
println "Uploading ${file.name} to Sonatype Central snapshots..."
112+
113+
def connection = new URL("https://central.sonatype.com/api/v1/publisher/snapshots/${project.group}/${project.name}/${project.version}/${file.name}").openConnection()
114+
connection.setRequestMethod("PUT")
115+
connection.setRequestProperty("Authorization", "Basic ${encodedCredentials}")
116+
connection.setRequestProperty("Content-Type", "application/octet-stream")
117+
connection.setDoOutput(true)
118+
119+
// Upload file content
120+
file.withInputStream { inputStream ->
121+
connection.outputStream << inputStream
122+
}
123+
124+
def responseCode = connection.responseCode
125+
if (responseCode >= 200 && responseCode < 300) {
126+
println "Successfully uploaded ${file.name}"
127+
} else {
128+
def errorResponse = connection.errorStream?.text ?: connection.inputStream?.text ?: "No error details"
129+
throw new GradleException("Failed to upload ${file.name}. Response code: ${responseCode}, Error: ${errorResponse}")
130+
}
131+
}
132+
}
133+
134+
println "All snapshot artifacts uploaded successfully to Sonatype Central Portal"
135+
}
86136
}
87137

88138
// Task to publish artifacts to local Maven repository

0 commit comments

Comments
 (0)