diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-12 21:41:05 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-01-12 21:41:05 -0800 |
commit | 91102940a0bcdd7efc1d13e43510c4a0e406ead2 (patch) | |
tree | 13d57ceea57a6627fa40e04c15ca25b58b63b5cc /scalalib/src/main/scala/mill/scalalib/PublishModule.scala | |
parent | cde65b142ca4c356134350525775d631015799ee (diff) | |
download | mill-91102940a0bcdd7efc1d13e43510c4a0e406ead2.tar.gz mill-91102940a0bcdd7efc1d13e43510c4a0e406ead2.tar.bz2 mill-91102940a0bcdd7efc1d13e43510c4a0e406ead2.zip |
Break up scalalib/Module.scala
Diffstat (limited to 'scalalib/src/main/scala/mill/scalalib/PublishModule.scala')
-rw-r--r-- | scalalib/src/main/scala/mill/scalalib/PublishModule.scala | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/scalalib/src/main/scala/mill/scalalib/PublishModule.scala b/scalalib/src/main/scala/mill/scalalib/PublishModule.scala new file mode 100644 index 00000000..1b1a0f44 --- /dev/null +++ b/scalalib/src/main/scala/mill/scalalib/PublishModule.scala @@ -0,0 +1,70 @@ +package mill +package scalalib + +import ammonite.ops._ +import mill.eval.{PathRef, Result} + +/** + * Configuration necessary for publishing a Scala module to Maven Central or similar + */ +trait PublishModule extends Module { outer => + import mill.scalalib.publish._ + + def pomSettings: T[PomSettings] + def publishVersion: T[String] = "0.0.1-SNAPSHOT" + + def pom = T { + val dependencies = + ivyDeps().map(Artifact.fromDep(_, scalaVersion(), scalaBinaryVersion())) + val pom = Pom(artifact(), dependencies, artifactName(), pomSettings()) + + val pomPath = T.ctx().dest / s"${artifactId()}-${publishVersion()}.pom" + write.over(pomPath, pom) + PathRef(pomPath) + } + + def ivy = T { + val dependencies = + ivyDeps().map(Artifact.fromDep(_, scalaVersion(), scalaBinaryVersion())) + val ivy = Ivy(artifact(), dependencies) + val ivyPath = T.ctx().dest / "ivy.xml" + write.over(ivyPath, ivy) + PathRef(ivyPath) + } + + def artifact: T[Artifact] = T { + Artifact(pomSettings().organization, artifactId(), publishVersion()) + } + + def publishLocal(): define.Command[Unit] = T.command { + LocalPublisher.publish( + jar = jar().path, + sourcesJar = sourcesJar().path, + docsJar = docsJar().path, + pom = pom().path, + ivy = ivy().path, + artifact = artifact() + ) + } + + def sonatypeUri: String = "https://oss.sonatype.org/service/local" + + def sonatypeSnapshotUri: String = "https://oss.sonatype.org/content/repositories/snapshots" + + def publish(credentials: String, gpgPassphrase: String): define.Command[Unit] = T.command { + val baseName = s"${artifactId()}-${publishVersion()}" + val artifacts = Seq( + jar().path -> s"${baseName}.jar", + sourcesJar().path -> s"${baseName}-sources.jar", + docsJar().path -> s"${baseName}-javadoc.jar", + pom().path -> s"${baseName}.pom" + ) + new SonatypePublisher( + sonatypeUri, + sonatypeSnapshotUri, + credentials, + gpgPassphrase, + T.ctx().log + ).publish(artifacts, artifact()) + } +} |