forked from playframework/play-ebean
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
133 lines (122 loc) · 4.29 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
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
// 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.scala3
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.0.0")
lazy val mimaSettings = Seq(
mimaPreviousArtifacts := previousVersion.map(organization.value %% moduleName.value % _).toSet,
mimaBinaryIssueFilters ++= Seq(
ProblemFilters.exclude[ReversedMissingMethodProblem]("play.db.ebean.EbeanConfig.generateEvolutionsScripts"),
)
)
lazy val root = project
.in(file("."))
.aggregate(core, plugin)
.disablePlugins(MimaPlugin)
.settings(
scalaVersion := scala3,
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, scala3),
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),
mimaPreviousArtifacts := Set.empty,
Compile / resourceGenerators += generateVersionFile.taskValue,
scriptedLaunchOpts ++= Seq(
s"-Dproject.version=${version.value}",
),
scriptedBufferLog := false,
scriptedDependencies := ((): Unit),
)
.settings(
(Compile / headerSources) ++=
(sourceDirectory.value / "sbt-test" ** ("*.java" || "*.sbt")).get
)
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)
}