Skip to content

Commit 631df22

Browse files
Gedochaotgodzik
andauthored
Migrate publishing to Sonatype Maven Central (#100)
* Migrate publishing to Sonatype Maven Central * Update build.mill.scala Co-authored-by: Tomasz Godzik <tgodzik@users.noreply.github.com> --------- Co-authored-by: Tomasz Godzik <tgodzik@users.noreply.github.com>
1 parent fab0573 commit 631df22

1 file changed

Lines changed: 25 additions & 15 deletions

File tree

build.mill.scala

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import scala.annotation.unused
1515
import scala.concurrent.duration.DurationInt
1616
import java.io.File
1717
import com.goyeau.mill.scalafix.ScalafixModule
18+
import com.lumidion.sonatype.central.client.core.{PublishingType, SonatypeCredentials}
19+
import mill.scalalib.publish.{Developer, License, PomSettings, VersionControl}
1820

1921
object Versions {
2022
def scala = "3.3.6"
@@ -247,10 +249,7 @@ def publishVersion0: Target[String] = Task {
247249
def ghOrg = "VirtusLab"
248250
def ghName = "java-class-name"
249251

250-
trait JavaClassNamePublishModule extends PublishModule {
251-
252-
import mill.scalalib.publish._
253-
252+
trait JavaClassNamePublishModule extends SonatypeCentralPublishModule {
254253
def pomSettings: Target[PomSettings] = PomSettings(
255254
description = artifactName(),
256255
organization = "org.virtuslab.scala-cli.java-class-name",
@@ -281,22 +280,31 @@ object ci extends Module {
281280
@unused
282281
def publishSonatype(tasks: mill.main.Tasks[PublishModule.PublishData]): Command[Unit] =
283282
Task.Command {
283+
val publishVersion = publishVersion0()
284+
System.err.println(s"Publish version: $publishVersion")
285+
val bundleName = s"org.virtuslab.scala-cli.java-class-name-java-class-name-$publishVersion"
286+
System.err.println(s"Publishing bundle: $bundleName")
284287
publishSonatype0(
285288
data = define.Target.sequence(tasks.value)(),
286289
log = Task.ctx().log,
287290
workspace = Task.workspace,
288-
env = Task.env
291+
env = Task.env,
292+
bundleName = bundleName
289293
)
290294
}
291295

292296
private def publishSonatype0(
293297
data: Seq[PublishModule.PublishData],
294298
log: mill.api.Logger,
295299
workspace: os.Path,
296-
env: Map[String, String]
300+
env: Map[String, String],
301+
bundleName: String
297302
): Unit = {
298303

299-
val credentials = sys.env("SONATYPE_USERNAME") + ":" + sys.env("SONATYPE_PASSWORD")
304+
val credentials = SonatypeCredentials(
305+
username = sys.env("SONATYPE_USERNAME"),
306+
password = sys.env("SONATYPE_PASSWORD")
307+
)
300308
val pgpPassword = sys.env("PGP_PASSWORD")
301309
val timeout = 10.minutes
302310

@@ -313,11 +321,8 @@ object ci extends Module {
313321
)
314322
set.head
315323
}
316-
val publisher = new scalalib.publish.SonatypePublisher(
317-
uri = "https://oss.sonatype.org/service/local",
318-
snapshotUri = "https://oss.sonatype.org/content/repositories/snapshots",
324+
val publisher = new SonatypeCentralPublisher(
319325
credentials = credentials,
320-
signed = true,
321326
gpgArgs = Seq(
322327
"--detach-sign",
323328
"--batch=true",
@@ -334,16 +339,21 @@ object ci extends Module {
334339
log = log,
335340
workspace = workspace,
336341
env = env,
337-
awaitTimeout = timeout.toMillis.toInt,
338-
stagingRelease = isRelease
342+
awaitTimeout = timeout.toMillis.toInt
339343
)
340344

341-
publisher.publishAll(isRelease, artifacts: _*)
345+
val publishingType = if (isRelease) PublishingType.AUTOMATIC else PublishingType.USER_MANAGED
346+
val finalBundleName = if (bundleName.nonEmpty) Some(bundleName) else None
347+
publisher.publishAll(
348+
publishingType = publishingType,
349+
singleBundleName = finalBundleName,
350+
artifacts = artifacts: _*
351+
)
342352
}
343353

344354
@unused
345355
def upload(directory: String = "artifacts/"): Command[Unit] = Task.Command {
346-
val version = publishVersion0()
356+
val version: String = publishVersion0()
347357

348358
val path = os.Path(directory, Task.workspace)
349359
val launchers = os.list(path).filter(os.isFile(_)).map { path =>

0 commit comments

Comments
 (0)