summaryrefslogtreecommitdiff
path: root/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala
diff options
context:
space:
mode:
authorrockjam <5min4eq.unity@gmail.com>2017-12-10 23:33:46 +0300
committerNikolay Tatarinov <5min4eq.unity@gmail.com>2017-12-20 01:17:16 +0300
commit9d19d740c5b387704e08fb89412b8318549a4fc5 (patch)
tree203c7ede2212c916195a82c2cf6578e9c755de7b /scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala
parent6a7f6cf910362cadf6b39f8c0795c46745e08742 (diff)
downloadmill-9d19d740c5b387704e08fb89412b8318549a4fc5.tar.gz
mill-9d19d740c5b387704e08fb89412b8318549a4fc5.tar.bz2
mill-9d19d740c5b387704e08fb89412b8318549a4fc5.zip
Add Sonatypype publishing;
now you can publish your module with `mill run MyModule.publish --credentials $SONATYPE_CREDENTIALS --gpgPassphrase $GPG_PASSPHRASE`
Diffstat (limited to 'scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala')
-rw-r--r--scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala142
1 files changed, 100 insertions, 42 deletions
diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala
index f7cb8963..949682ca 100644
--- a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala
+++ b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala
@@ -3,11 +3,12 @@ package scalaplugin
import ammonite.ops._
import coursier.{Cache, MavenRepository, Repository}
-import mill.define.{Source, Task}
+import mill.define.Task
import mill.define.Task.{Module, TaskModule}
import mill.eval.{PathRef, Result}
import mill.modules.Jvm
import mill.modules.Jvm.{createAssembly, createJar, interactiveSubprocess, subprocess}
+
import Lib._
trait TestScalaModule extends ScalaModule with TaskModule {
override def defaultCommandName() = "test"
@@ -48,7 +49,8 @@ trait TestScalaModule extends ScalaModule with TaskModule {
}
}
}
-trait ScalaModule extends Module with TaskModule{ outer =>
+
+trait ScalaModule extends Module with TaskModule { outer =>
def defaultCommandName() = "run"
trait Tests extends TestScalaModule{
def scalaVersion = outer.scalaVersion()
@@ -197,38 +199,42 @@ trait ScalaModule extends Module with TaskModule{ outer =>
(runDepClasspath().filter(_.path.ext != "pom") ++
Seq(resources(), compile().classes)).map(_.path).filter(exists)
}
+
def assembly = T{
- val outDir = T.ctx().dest/up
- val n = name()
- val v = version()
- val jarName = s"${n}-${v}.jar"
- val dest = outDir/jarName
- createAssembly(dest, assemblyClasspath(), prependShellScript = prependShellScript())
+ createAssembly(assemblyClasspath(), prependShellScript = prependShellScript())
}
def classpath = T{ Seq(resources(), compile().classes) }
def jar = T{
- val outDir = T.ctx().dest/up
- val n = name()
- val v = version()
- val jarName = s"${n}-${v}.jar"
- val dest = outDir/jarName
- createJar(dest, Seq(resources(), compile().classes).map(_.path).filter(exists), mainClass())
- PathRef(dest)
+ createJar(
+ Seq(resources(), compile().classes).map(_.path).filter(exists),
+ mainClass()
+ )
}
- def sourcesJar = T{
- val outDir = T.ctx().dest/up
- val n = name()
- val v = version()
- val jarName = s"${n}-${v}-sources.jar"
- val dest = outDir/jarName
+ def docsJar = T {
+ val outDir = T.ctx().dest
- val inputs = Seq(sources(), resources()).map(_.path).filter(exists)
+ val javadocDir = outDir / 'javadoc
+ mkdir(javadocDir)
+
+ val options = {
+ val files = ls.rec(sources().path).filter(_.isFile).map(_.toNIO.toString)
+ files ++ Seq("-d", javadocDir.toNIO.toString, "-usejavacp")
+ }
+
+ subprocess(
+ "scala.tools.nsc.ScalaDoc",
+ compileDepClasspath().filterNot(_.path.ext == "pom").map(_.path),
+ options = options
+ )
- createJar(dest, inputs)
- PathRef(dest)
+ createJar(Seq(javadocDir))(outDir / "javadoc.jar")
+ }
+
+ def sourcesJar = T {
+ createJar(Seq(sources(), resources()).map(_.path).filter(exists))(T.ctx().dest / "sources.jar")
}
def run() = T.command{
@@ -247,28 +253,80 @@ trait ScalaModule extends Module with TaskModule{ outer =>
options = Seq("-usejavacp")
)
}
+}
+
+trait PublishModule extends ScalaModule { outer =>
+ import mill.scalaplugin.publish._
+
+ def publishName: T[String] = basePath.last.toString
+ def publishVersion: T[String] = "0.0.1-SNAPSHOT"
+ def pomSettings: T[PomSettings]
+
+ // publish artifact with name "mill_2.12.4" instead of "mill_2.12"
+ def publishWithFullScalaVersion: Boolean = false
+
+ def artifactScalaVersion: T[String] = T {
+ if (publishWithFullScalaVersion) scalaVersion()
+ else scalaBinaryVersion()
+ }
+
+ def pom = T {
+ val dependencies =
+ ivyDeps().map(Artifact.fromDep(_, scalaVersion(), scalaBinaryVersion()))
+ val pom = Pom(artifact(), dependencies, publishName(), pomSettings())
+
+ val pomPath = T.ctx().dest / s"${publishName()}_${artifactScalaVersion()}-${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, s"${publishName()}_${artifactScalaVersion()}", 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 organization: T[String] = "acme"
- def name: T[String] = pwd.last.toString
- def version: T[String] = "0.0.1-SNAPSHOT"
-
- // build artifact name as "mill-2.12.4" instead of "mill-2.12"
- def useFullScalaVersionForPublish: Boolean = false
-
- def publishLocal() = T.command {
- import publish._
- val file = jar()
- val scalaFull = scalaVersion()
- val scalaBin = scalaBinaryVersion()
- val useFullVersion = useFullScalaVersionForPublish
- val deps = ivyDeps()
- val dependencies = deps.map(d => Artifact.fromDep(d, scalaFull, scalaBin))
- val artScalaVersion = if (useFullVersion) scalaFull else scalaBin
- val artifact = ScalaArtifact(organization(), name(), version(), artScalaVersion)
- LocalPublisher.publish(file, artifact, dependencies)
+ def sonatypeSnapshotUri: String = "https://oss.sonatype.org/content/repositories/snapshots"
+
+ def publish(credentials: String, gpgPassphrase: String): define.Command[Unit] = T.command {
+ val baseName = s"${publishName()}_${artifactScalaVersion()}-${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())
}
}
+
trait SbtScalaModule extends ScalaModule { outer =>
def basePath: Path
override def sources = T.source{ basePath / 'src / 'main / 'scala }