-
-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathbuild.sbt
More file actions
163 lines (150 loc) · 5.32 KB
/
Copy pathbuild.sbt
File metadata and controls
163 lines (150 loc) · 5.32 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com>
import Dependencies.ScalaVersions.scala212
import Dependencies.ScalaVersions.scala213
import Dependencies.ScalaVersions.scala3App
import Dependencies.ScalaVersions.scala3Plugin
import Dependencies.Versions
import com.typesafe.tools.mima.core._
import sbt.Append.appendSeq
import xsbti.compile.CompileAnalysis
// Customise sbt-dynver's behaviour to make it work with tags which aren't v-prefixed
ThisBuild / dynverVTagPrefix := false
// Sanity-check: assert that version comes from a tag (e.g. not a too-shallow clone)
// https://github.com/dwijnand/sbt-dynver/#sanity-checking-the-version
Global / onLoad := (Global / onLoad).value.andThen { s =>
dynverAssertTagVersion.value
s
}
val previousVersion: Option[String] = Some("8.3.0")
lazy val mimaSettings = Seq(
mimaPreviousArtifacts := previousVersion.map(organization.value %% moduleName.value % _).toSet,
mimaBinaryIssueFilters ++= Seq(
ProblemFilters.exclude[MissingTypesProblem]("play.db.ebean.DefaultEbeanConfig$EbeanConfigParser"),
)
)
ThisBuild / javafmtFormatterCompatibleJavaVersion := 17
lazy val root = project
.in(file("."))
.aggregate(core, plugin)
.disablePlugins(MimaPlugin)
.settings(
scalaVersion := scala3App,
name := "play-ebean-root",
crossScalaVersions := Nil,
publish / skip := true,
)
.settings(
(Compile / headerSources) ++=
((baseDirectory.value ** ("*.properties" || "*.md" || "*.sbt"))
--- (baseDirectory.value ** "target" ** "*")
--- (baseDirectory.value / ".github" ** "*")
--- (baseDirectory.value / "docs" ** "*")
--- (baseDirectory.value / "sbt-play-ebean" ** "*")).get ++
(baseDirectory.value / "project" ** "*.scala" --- (baseDirectory.value ** "target" ** "*")).get
)
lazy val core = project
.in(file("play-ebean"))
.settings(
name := "play-ebean",
scalaVersion := scala213,
crossScalaVersions := Seq(scala213, scala3App),
Dependencies.ebean,
mimaSettings,
Compile / compile := enhanceEbeanClasses(
(Compile / dependencyClasspath).value,
(Compile / compile).value,
(Compile / classDirectory).value,
"play/db/ebean/**"
),
)
lazy val plugin = project
.in(file("sbt-play-ebean"))
.enablePlugins(SbtPlugin)
.settings(
name := "sbt-play-ebean",
organization := "org.playframework",
Dependencies.plugin,
addSbtPlugin("org.playframework" % "sbt-plugin" % Versions.play),
scalaVersion := scala212,
crossScalaVersions := Seq(scala212, scala3Plugin),
pluginCrossBuild / sbtVersion := {
scalaBinaryVersion.value match {
case "2.12" => "1.12.9"
case _ => "2.0.0-RC11"
}
},
scalacOptions ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, _)) => Seq("-Xsource:3")
case _ => Seq.empty
}
},
mimaPreviousArtifacts := Set.empty,
Compile / resourceGenerators += generateVersionFile.taskValue,
// Use the current lane-based app Scala as a fallback for local runs without scripted.scala.version.
scriptedLaunchOpts ++= Seq(
s"-Dproject.version=${version.value}",
s"-Dscala.version=${resolveScriptedScala(
sys.props.getOrElse(
"scripted.scala.version",
if (scalaBinaryVersion.value == "2.12") scala213 else scala3App
)
)}",
),
scriptedBufferLog := false,
scriptedDependencies := publishLocal.value,
)
.settings(
(Compile / headerSources) ++=
(sourceDirectory.value / "sbt-test" ** ("*.java" || "*.sbt")).get
)
def resolveScriptedScala(version: String): String =
version match {
case "scala212" | "2.12.x" => scala212
case "scala213" | "2.13.x" => scala213
case "scala3" | "3.x" => scala3App
case exact => exact
}
def sbtPluginDep(moduleId: ModuleID, sbtVersion: String, scalaVersion: String) = {
Defaults.sbtPluginExtra(
moduleId,
CrossVersion.binarySbtVersion(sbtVersion),
CrossVersion.binaryScalaVersion(scalaVersion)
)
}
// Ebean enhancement
def enhanceEbeanClasses(
classpath: Classpath,
analysis: CompileAnalysis,
classDirectory: File,
pkg: String
): CompileAnalysis = {
// Ebean (really hacky sorry)
val cp = classpath.map(_.data.toURI.toURL).toArray :+ classDirectory.toURI.toURL
val cl = new java.net.URLClassLoader(cp)
val t = cl
.loadClass("io.ebean.enhance.Transformer")
.getConstructor(classOf[ClassLoader], classOf[String])
.newInstance(cl, "debug=0")
.asInstanceOf[AnyRef]
val ft = cl
.loadClass("io.ebean.enhance.ant.OfflineFileTransform")
.getConstructor(
t.getClass,
classOf[ClassLoader],
classOf[String]
)
.newInstance(t, ClassLoader.getSystemClassLoader, classDirectory.getAbsolutePath)
.asInstanceOf[AnyRef]
ft.getClass.getDeclaredMethod("process", classOf[String]).invoke(ft, pkg)
analysis
}
// Version file
def generateVersionFile =
Def.task {
val version = (core / Keys.version).value
val file = (Compile / resourceManaged).value / "play-ebean.version.properties"
val content = s"play-ebean.version=$version"
IO.write(file, content)
Seq(file)
}