-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
93 lines (76 loc) · 2.69 KB
/
build.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
ThisBuild / useCoursier := false
Global / onChangedBuildSource := ReloadOnSourceChanges
inThisBuild(Seq(
organization := "de.djini",
version := "0.4.0",
scalaVersion := "3.1.0",
scalacOptions ++= Seq(
"-feature",
"-deprecation",
"-unchecked",
"-Wunused:all",
"-Xfatal-warnings",
"-Ykind-projector:underscores",
),
versionScheme := Some("early-semver"),
conflictManager := ConflictManager.strict
))
lazy val `kapsel` =
project.in(file("."))
.aggregate(
`kapsel-start`,
`kapsel-example`,
)
.settings(
publishArtifact := false
//publish := {},
//publishLocal := {}
)
//------------------------------------------------------------------------------
lazy val `kapsel-start` =
project.in(file("modules/start"))
.settings(
// this is a pure java project
crossPaths := false,
autoScalaLibrary := false,
// stay compatible with java 8
Compile / javacOptions ++= Seq("-source", "1.8"),
Compile / compile / javacOptions ++= Seq("-target", "1.8"),
)
//------------------------------------------------------------------------------
lazy val `kapsel-example` =
project.in(file("modules/example"))
.settings(
TaskKey[File]("kapsel") := {
val kapselClass = (`kapsel-start` / Runtime / products).value(0) / "Kapsel.class"
val bundleId = name.value + "-" + version.value
val bundleMainClass = (Compile / mainClass).value getOrElse (sys error "missing main class")
val bundleClassPath = (Compile / fullClasspathAsJars).value map (_.data)
// prevent name clashes in the classpath
val classPath = bundleClassPath.zipWithIndex map { case (file,index) => file -> s"$index-${file.getName}" }
val kapselDir = target.value / "kapsel"
IO delete kapselDir
// build kapsel jar without exec header
val tempJar = kapselDir / s"headerless-${bundleId}.jar"
val manifest = new java.util.jar.Manifest
manifest.getMainAttributes.putValue("Main-Class", "Kapsel")
manifest.getMainAttributes.putValue("Kapsel-Application-Id", bundleId)
manifest.getMainAttributes.putValue("Kapsel-Jvm-Options", "-Xmx128m")
manifest.getMainAttributes.putValue("Kapsel-Class-Path", classPath.map(_._2).mkString(" "))
manifest.getMainAttributes.putValue("Kapsel-Main-Class", bundleMainClass)
val bundleContent = (kapselClass -> "Kapsel.class") +: classPath
IO jar (bundleContent, tempJar, manifest, None)
// build kapsel jar with exec header
val bundleJar = kapselDir / s"${bundleId}.jar"
IO write (
bundleJar,
""" |#/bin/sh
|exec java -jar "$0" "$@"
|""".stripMargin
)
IO append (bundleJar, IO readBytes tempJar)
bundleJar setExecutable (true, false)
streams.value.log info s"built kapsel bundle $bundleJar"
bundleJar
}
)