Skip to content

Commit 60e0298

Browse files
committed
switch to the maven-deployer plugin
1 parent 0ea959a commit 60e0298

11 files changed

+78
-59
lines changed

build.gradle.kts

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import io.github.zenhelix.gradle.plugin.task.PublishBundleMavenCentralTask
1+
import io.github.danielliu1123.deployer.PublishingType
22
import pl.allegro.tech.build.axion.release.domain.PredefinedVersionCreator
33

44
plugins {
55
`maven-publish`
66
alias(libs.plugins.axion)
7-
alias(libs.plugins.mavenCentralPublish) apply false
7+
alias(libs.plugins.mavenDeployer)
8+
id("tel.schich.javacan.convention.root")
89
}
910

1011
tasks.wrapper {
@@ -13,6 +14,40 @@ tasks.wrapper {
1314

1415
description = "JavaCAN is a binding to Linux' socketcan subsystem that feels native to Java developers."
1516

17+
private fun Project.getSecret(name: String): Provider<String> = provider {
18+
val env = System.getenv(name)
19+
?.ifBlank { null }
20+
if (env != null) {
21+
return@provider env
22+
}
23+
24+
val propName = name.split("_")
25+
.map { it.lowercase() }
26+
.joinToString(separator = "") { word ->
27+
word.replaceFirstChar { it.uppercase() }
28+
}
29+
.replaceFirstChar { it.lowercase() }
30+
31+
property(propName) as String
32+
}
33+
34+
deploy {
35+
// dirs to upload, they will all be packaged into one bundle
36+
dirs = provider {
37+
allprojects
38+
.map { it.layout.buildDirectory.dir("repo").get().asFile }
39+
.filter { it.exists() }
40+
.toList()
41+
}
42+
username = project.getSecret("MAVEN_CENTRAL_PORTAL_USERNAME")
43+
password = project.getSecret("MAVEN_CENTRAL_PORTAL_PASSWORD")
44+
publishingType = if (Constants.CI) {
45+
PublishingType.WAIT_FOR_PUBLISHED
46+
} else {
47+
PublishingType.USER_MANAGED
48+
}
49+
}
50+
1651
scmVersion {
1752
tag {
1853
prefix = "javacan-"
@@ -30,6 +65,7 @@ allprojects {
3065
group = "tel.schich"
3166
version = gitVersion
3267
}
68+
val isSnapshot = project.version.toString().endsWith("-SNAPSHOT")
3369

3470
val publishAllToMavenLocal by tasks.registering(DefaultTask::class) {
3571
group = "publishing"
@@ -56,22 +92,25 @@ val testAll by tasks.registering(DefaultTask::class) {
5692

5793
val mavenCentralDeploy by tasks.registering(DefaultTask::class) {
5894
group = "publishing"
59-
val isSnapshot = project.version.toString().endsWith("-SNAPSHOT")
60-
61-
if (isSnapshot) {
62-
logger.lifecycle("Snapshot deployment!")
63-
for (project in allprojects) {
64-
val tasks = project.tasks
65-
.withType<PublishToMavenRepository>()
66-
.matching { it.repository.name == "mavenCentralSnapshots" }
67-
dependsOn(tasks)
68-
}
95+
96+
val repo = if (isSnapshot) {
97+
Constants.SNAPSHOTS_REPO
6998
} else {
70-
logger.lifecycle("Release deployment!")
71-
for (project in allprojects) {
72-
val tasks = project.tasks
73-
.withType<PublishBundleMavenCentralTask>()
74-
dependsOn(tasks)
99+
dependsOn(tasks.deploy)
100+
Constants.RELEASES_REPO
101+
}
102+
for (project in allprojects) {
103+
val publishTasks = project.tasks
104+
.withType<PublishToMavenRepository>()
105+
.matching { it.repository.name == repo }
106+
dependsOn(publishTasks)
107+
}
108+
109+
doFirst {
110+
if (isSnapshot) {
111+
logger.lifecycle("Snapshot deployment!")
112+
} else {
113+
logger.lifecycle("Release deployment!")
75114
}
76115
}
77116
}

conventions/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ repositories {
99

1010
dependencies {
1111
api(plugin(libs.plugins.dockcross))
12-
implementation(plugin(libs.plugins.mavenCentralPublish))
1312
}
1413

1514
fun plugin(plugin: Provider<PluginDependency>) =

conventions/src/main/kotlin/ArchDetectUtil.kt

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object Constants {
2+
const val ARCH_DETECT_CONFIG = "archDetectConfiguration"
3+
4+
const val SNAPSHOTS_REPO = "mavenCentralSnapshots"
5+
const val RELEASES_REPO = "mavenLocal"
6+
7+
val CI = System.getenv("CI") != null
8+
}

conventions/src/main/kotlin/tel.schich.javacan.convention.base.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plugins {
22
`java-library`
33
`java-test-fixtures`
4+
id("tel.schich.javacan.convention.root")
45
}
56

67
val javaComponent = components["java"] as AdhocComponentWithVariants

conventions/src/main/kotlin/tel.schich.javacan.convention.native.gradle.kts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ plugins {
77
id("tel.schich.dockcross")
88
}
99

10-
val ci = System.getenv("CI") != null
11-
12-
val archDetectConfiguration = configurations.register(ARCH_DETECT_CONFIGURATION_NAME) {
10+
val archDetectConfiguration = configurations.register(Constants.ARCH_DETECT_CONFIG) {
1311
isCanBeConsumed = true
1412
}
1513

@@ -135,7 +133,7 @@ for (target in targets) {
135133
image = dockcrossImage
136134
containerName = "dockcross-${project.name}-$classifier"
137135

138-
if (ci) {
136+
if (Constants.CI) {
139137
runner(DockerRunner())
140138
doLast {
141139
providers.exec {

conventions/src/main/kotlin/tel.schich.javacan.convention.published.gradle.kts

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,25 @@
1-
import io.github.zenhelix.gradle.plugin.extension.PublishingType
2-
31
plugins {
42
id("tel.schich.javacan.convention.base")
53
signing
64
`maven-publish`
7-
id("io.github.zenhelix.maven-central-publish")
85
}
96

10-
val ci = System.getenv("CI") != null
11-
127
java {
138
withSourcesJar()
149
withJavadocJar()
1510
}
1611

17-
private fun Project.getSecret(name: String): Provider<String> = provider {
18-
val env = System.getenv(name)
19-
?.ifBlank { null }
20-
if (env != null) {
21-
return@provider env
22-
}
23-
24-
val propName = name.split("_")
25-
.map { it.lowercase() }
26-
.joinToString(separator = "") { word ->
27-
word.replaceFirstChar { it.uppercase() }
28-
}
29-
.replaceFirstChar { it.lowercase() }
30-
31-
property(propName) as String
32-
}
33-
34-
mavenCentralPortal {
35-
credentials {
36-
username = project.getSecret("MAVEN_CENTRAL_PORTAL_USERNAME")
37-
password = project.getSecret("MAVEN_CENTRAL_PORTAL_PASSWORD")
38-
}
39-
publishingType = PublishingType.AUTOMATIC
40-
}
41-
4212
publishing {
4313
repositories {
4414
maven {
45-
name = "mavenCentralSnapshots"
15+
name = Constants.SNAPSHOTS_REPO
4616
url = uri("https://central.sonatype.com/repository/maven-snapshots/")
4717
credentials(PasswordCredentials::class)
4818
}
19+
maven {
20+
name = Constants.RELEASES_REPO
21+
url = layout.buildDirectory.dir("repo").get().asFile.toURI()
22+
}
4923
}
5024

5125
publications {
@@ -91,7 +65,7 @@ when {
9165
sign(publishing.publications)
9266
}
9367
}
94-
!ci -> {
68+
!Constants.CI -> {
9569
logger.lifecycle("Not running in CI, using the gpg command!")
9670
signing {
9771
useGpgCmd()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// yep, this is an empty plugin just to have something to pull into the root project to have access to shared code.

core-arch-detect/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ val nativeLibs by configurations.getting
66

77
dependencies {
88
api(project(":core"))
9-
nativeLibs(project(mapOf("path" to ":core", "configuration" to ARCH_DETECT_CONFIGURATION_NAME)))
9+
nativeLibs(project(mapOf("path" to ":core", "configuration" to Constants.ARCH_DETECT_CONFIG)))
1010
}
1111

1212
publishing.publications.withType<MavenPublication>().configureEach {

epoll-arch-detect/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ val nativeLibs by configurations.getting
66

77
dependencies {
88
api(project(":epoll"))
9-
nativeLibs(project(mapOf("path" to ":epoll", "configuration" to ARCH_DETECT_CONFIGURATION_NAME)))
9+
nativeLibs(project(mapOf("path" to ":epoll", "configuration" to Constants.ARCH_DETECT_CONFIG)))
1010
}
1111

1212
publishing.publications.withType<MavenPublication>().configureEach {

0 commit comments

Comments
 (0)