summaryrefslogtreecommitdiff
path: root/scalaplugin
diff options
context:
space:
mode:
authorrockjam <5min4eq.unity@gmail.com>2017-11-29 18:42:42 +0300
committerrockjam <5min4eq.unity@gmail.com>2017-11-30 13:30:45 +0300
commit2222c14b405e5f2c429380293ed8165cb84fa156 (patch)
tree9ce1ac56755b69e42aac48ba34baeb45f0d72f22 /scalaplugin
parent54f2af0a974e28b81026f503eff420fad2869d2f (diff)
downloadmill-2222c14b405e5f2c429380293ed8165cb84fa156.tar.gz
mill-2222c14b405e5f2c429380293ed8165cb84fa156.tar.bz2
mill-2222c14b405e5f2c429380293ed8165cb84fa156.zip
mainClass support
Diffstat (limited to 'scalaplugin')
-rw-r--r--scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala3
-rw-r--r--scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala22
2 files changed, 23 insertions, 2 deletions
diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala
index 6b67b708..b87ba6b3 100644
--- a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala
+++ b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala
@@ -224,6 +224,7 @@ trait ScalaModule extends Module with TaskModule{ outer =>
override def projectDeps = Seq(outer)
}
def scalaVersion: T[String]
+ def mainClass: T[Option[String]] = None
def scalaBinaryVersion = T{ scalaVersion().split('.').dropRight(1).mkString(".") }
def ivyDeps = T{ Seq[Dep]() }
@@ -349,7 +350,7 @@ trait ScalaModule extends Module with TaskModule{ outer =>
def classpath = T{ Seq(resources(), compile()) }
def jar = T{
val dest = T.ctx().dest
- createJar(dest, Seq(resources(), compile()).map(_.path).filter(exists))
+ createJar(dest, Seq(resources(), compile()).map(_.path).filter(exists), mainClass())
PathRef(dest)
}
diff --git a/scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala b/scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala
index 03b9b285..f4a4e993 100644
--- a/scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala
+++ b/scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala
@@ -17,6 +17,10 @@ trait HelloWorldModule extends ScalaModule {
object HelloWorld extends HelloWorldModule
+object HelloWorldWithMain extends HelloWorldModule {
+ override def mainClass = Some("Main")
+}
+
object HelloWorldWarnUnused extends HelloWorldModule {
override def scalacOptions = T(Seq("-Ywarn-unused"))
}
@@ -200,7 +204,23 @@ object HelloWorldTests extends TestSuite {
jarFiles.forall(expectedFiles.contains)
)
}
- // TODO: check that we can `java -jar` produced jar
+ 'runJar - {
+ val Right((result, evalCount)) =
+ eval(HelloWorldWithMain.jar, Discovered.mapping(HelloWorldWithMain))
+
+ assert(
+ exists(result.path),
+ evalCount > 0
+ )
+
+ %("scala", result.path)
+
+ val runResult = workspacePath / "hello-mill"
+ assert(
+ exists(runResult),
+ read(runResult) == "hello rockjam, your age is: 25"
+ )
+ }
}
}