forked from playframework/play-ebean
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
101 lines (86 loc) · 3.25 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
import sbt.inc.Analysis
val PlayVersion = playVersion(sys.props.getOrElse("play.version", "2.5.0-M1"))
val PlayEnhancerVersion = "1.1.0"
lazy val root = project
.in(file("."))
.enablePlugins(PlayRootProject)
.aggregate(core,plugin)
.settings(
name := "play-ebean-root",
releaseCrossBuild := false
)
lazy val core = project
.in(file("play-ebean"))
.enablePlugins(Playdoc, PlayLibrary)
.settings(
name := "play-ebean",
libraryDependencies ++= playEbeanDeps,
compile in Compile := enhanceEbeanClasses(
(dependencyClasspath in Compile).value,
(compile in Compile).value,
(classDirectory in Compile).value,
"play/db/ebean/**"
)
)
lazy val plugin = project
.in(file("sbt-play-ebean"))
.enablePlugins(PlaySbtPlugin)
.settings(
name := "sbt-play-ebean",
organization := "com.typesafe.sbt",
libraryDependencies ++= sbtPlayEbeanDeps,
addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % PlayEnhancerVersion),
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % PlayVersion),
resourceGenerators in Compile <+= generateVersionFile,
scriptedLaunchOpts ++= Seq("-Dplay-ebean.version=" + version.value),
scriptedDependencies := {
val () = publishLocal.value
val () = (publishLocal in core).value
}
)
playBuildRepoName in ThisBuild := "play-ebean"
playBuildExtraTests := {
(scripted in plugin).toTask("").value
}
playBuildExtraPublish := {
(PgpKeys.publishSigned in plugin).value
}
// Dependencies
def playEbeanDeps = Seq(
"com.typesafe.play" %% "play-java-jdbc" % PlayVersion,
"com.typesafe.play" %% "play-jdbc-evolutions" % PlayVersion,
"org.avaje.ebeanorm" % "avaje-ebeanorm" % "6.8.1",
avajeEbeanormAgent,
avajeEbeanormQueryAgent,
avajeGenerator,
"com.typesafe.play" %% "play-test" % PlayVersion % Test
)
def sbtPlayEbeanDeps = Seq(
avajeEbeanormAgent,
avajeEbeanormQueryAgent,
avajeGenerator,
"com.typesafe" % "config" % "1.3.0"
)
def avajeEbeanormAgent = "org.avaje.ebeanorm" % "avaje-ebeanorm-agent" % "4.7.1"
def avajeEbeanormQueryAgent = "org.avaje.ebeanorm" % "avaje-ebeanorm-typequery-agent" % "1.5.1"
def avajeGenerator = "org.avaje.ebeanorm" % "avaje-ebeanorm-typequery-generator" % "1.5.1"
// Ebean enhancement
def enhanceEbeanClasses(classpath: Classpath, analysis: Analysis, classDirectory: File, pkg: String): Analysis = {
// 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("com.avaje.ebean.enhance.agent.Transformer").getConstructor(classOf[Array[URL]], classOf[String]).newInstance(cp, "debug=0").asInstanceOf[AnyRef]
val ft = cl.loadClass("com.avaje.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 = (Keys.version in core).value
val file = (resourceManaged in Compile).value / "play-ebean.version.properties"
val content = s"play-ebean.version=$version"
IO.write(file, content)
Seq(file)
}