-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: publish the gradle module metadata
- avoid using the gradle bintray plugin, which doesn't upload the module metadata - sign locally rather than with bintray - publish the signed artefacts using the native maven-publish plugin - use a custom task that uses the bintray API to sync with Maven Central fix #56
- Loading branch information
Showing
5 changed files
with
121 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
.gradle | ||
/build/ | ||
build/ | ||
!gradle/wrapper/gradle-wrapper.jar | ||
|
||
### STS ### | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation("com.squareup.okhttp3:okhttp:4.8.1") | ||
implementation(gradleApi()) | ||
} |
66 changes: 66 additions & 0 deletions
66
buildSrc/src/main/kotlin/com/ninjasquad/gradle/MavenSyncTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.ninjasquad.gradle | ||
|
||
import okhttp3.MediaType.Companion.toMediaType | ||
import okhttp3.OkHttpClient | ||
import okhttp3.Request | ||
import okhttp3.RequestBody.Companion.toRequestBody | ||
import okhttp3.Credentials | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.GradleException | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.TaskAction | ||
import java.io.IOException | ||
import java.time.Duration | ||
|
||
open class MavenSyncTask : DefaultTask() { | ||
@Input | ||
lateinit var sonatypeUsername: String | ||
|
||
@Input | ||
lateinit var sonatypePassword: String | ||
|
||
@Input | ||
lateinit var bintrayUsername: String | ||
|
||
@Input | ||
lateinit var bintrayPassword: String | ||
|
||
@Input | ||
lateinit var bintrayRepoName: String | ||
|
||
@Input | ||
lateinit var bintrayPackageName: String | ||
|
||
@Input | ||
var version = project.version.toString() | ||
|
||
@TaskAction | ||
fun sync() { | ||
println("synchronizing with Maven central...") | ||
val client = OkHttpClient.Builder().readTimeout(Duration.ofMinutes(5L)).build() | ||
val jsonBody = | ||
// language=json | ||
""" | ||
{ | ||
"username": "$sonatypeUsername", | ||
"password": "$sonatypePassword", | ||
"close": "1" | ||
} | ||
""".trimIndent() | ||
val request: Request = Request.Builder() | ||
.header("Authorization", Credentials.basic(bintrayUsername, bintrayPassword)) | ||
.url("https://api.bintray.com/maven_central_sync/$bintrayUsername/$bintrayRepoName/$bintrayPackageName/versions/$version") | ||
.post(jsonBody.toRequestBody("application/json".toMediaType())) | ||
.build() | ||
try { | ||
client.newCall(request).execute().use { response -> | ||
if (!response.isSuccessful) { | ||
throw GradleException("Maven sync failed with status " + response.code + " and body " + response.body?.string()) | ||
} | ||
println(response.body?.string()) | ||
} | ||
} catch (e: IOException) { | ||
throw GradleException("Maven sync failed", e) | ||
} | ||
} | ||
} |