-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sbt
136 lines (116 loc) · 5.26 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
134
135
136
import sbt._
import Keys._
lazy val buildSettings = Seq(
name := "trader4s",
version := "0.1",
description := "Reliable execution and fast market data for IBKR",
scalaVersion := "2.13.6",
javacOptions := Seq("-source", "11", "-target", "11"),
resolvers += Resolver.sbtPluginRepo("releases"),
scalacOptions ++= Seq("-Xfatal-warnings", "-feature", "-deprecation", "-Ywarn-value-discard"),
Test / fork := true,
// Test / javaOptions += s"-Dlogback.configurationFile=$logbackXmlPath",
Test / javaOptions += s"-Dfile.ending=UTF8",
// Test / javaOptions += s"-Djavax.net.debug=all",
Test / scalacOptions ++= Seq("-Yrangepos"),
Global / onChangedBuildSource := ReloadOnSourceChanges,
addCompilerPlugin(("org.typelevel" %% "kind-projector" % "0.13.0").cross(CrossVersion.full)),
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1")
// Test / javaOptions += "-Dlogback.statusListenerClass=ch.qos.logback.core.status.OnConsoleStatusListener"
)
lazy val sbtAssemblySettings = Seq(
)
lazy val formatting = Seq(
)
lazy val allSettings = buildSettings ++ sbtAssemblySettings ++ formatting
lazy val processMapperAnnotations = taskKey[Unit]("Process Object Mapper annotations in compiled Scala classes")
lazy val compileMapperGeneratedSources = taskKey[Unit]("Compile the sources that were generated by the Object Mapper")
def runCommand(command: String, message: => String, log: Logger): Unit = {
import scala.sys.process._
val result = command !
if (result != 0) {
log.error(message)
sys.error("Failed running command: " + command)
}
}
lazy val ibCassandraModel = project
.settings(moduleName := "cat-trader-cassandra-model")
.settings(allSettings)
.settings(
Compile / unmanagedJars += file("/Users/pavel.voropaev/IdeaProjects/mltrader/thirdPartyJars/ibkr/ApiDemo.jar"),
Compile / unmanagedJars += file("/Users/pavel.voropaev/IdeaProjects/mltrader/thirdPartyJars/ibkr/TwsApi_debug.jar")
)
.settings(
libraryDependencies ++= Seq(
Dependencies.Libraries.catsEffect,
Dependencies.Libraries.fs2rx,
Dependencies.Libraries.javaDriverMapperRuntime,
Dependencies.Libraries.javaDriverMapperProcessor % "provided"
),
processMapperAnnotations := {
val log = streams.value.log
log.info("Processing Object Mapper annotations in compiled Scala classes...")
val classpath = ((Compile / products).value ++ (Compile / dependencyClasspath).value.files).mkString(":")
val sourceDirectory = (Compile / classDirectory).value
val classesToProcess = (sourceDirectory ** ("*.class" -- ("*Builder.class" || "*MapperGenerated.class")))
.getPaths()
.map(_.stripPrefix(sourceDirectory.getAbsolutePath + "/").stripSuffix(".class").replaceAll("/", "."))
.mkString(" ")
val destinationDirectory = (Compile / sourceManaged).value / "mapper"
destinationDirectory.mkdirs()
val processor = "com.datastax.oss.driver.internal.mapper.processor.MapperProcessor"
val command =
s"""javac
| -classpath $classpath
| -proc:only -processor $processor
| -d $destinationDirectory
| $classesToProcess""".stripMargin
runCommand(command, "Failed to run Object Mapper processor", log)
log.info("Done processing Object Mapper annotate ons in compiled Scala classes")
},
compileMapperGeneratedSources := {
val log = streams.value.log
log.info("Compiling Object Mapper generated sources...")
val classpath = ((Compile / products).value ++ (Compile / dependencyClasspath).value.files).mkString(":")
val sourceDirectory = (Compile / sourceManaged).value / "mapper"
val javaSources = (sourceDirectory ** "*.java").getPaths().mkString(" ")
val command =
s"""javac
| -classpath $classpath
| -d ${(Compile / classDirectory).value}
| $javaSources""".stripMargin
runCommand(command, "Failed to compile mapper-generated sources", log)
log.info("Done compiling Object Mapper generated sources")
},
Compile / compileMapperGeneratedSources := (Compile / compileMapperGeneratedSources)
.dependsOn(Compile / processMapperAnnotations)
.value,
Compile / packageBin := (Compile / packageBin).dependsOn(Compile / compileMapperGeneratedSources).value
)
lazy val ibFeed = project
.settings(moduleName := "cat-trader-core")
.settings(allSettings)
.settings(
Compile / compile := (Compile / compile).dependsOn(ibCassandraModel / Compile / compileMapperGeneratedSources).value
)
.settings(
libraryDependencies ++= Seq(
Dependencies.Libraries.cassandraMigrator,
Dependencies.Libraries.cassandraCore,
Dependencies.Libraries.catsCore,
Dependencies.Libraries.pureConfig,
Dependencies.Libraries.kittens,
Dependencies.Libraries.catsEffect,
Dependencies.Libraries.scalaLogging,
Dependencies.Libraries.log4cats,
Dependencies.Libraries.logback,
Dependencies.Libraries.fs2io,
Dependencies.Libraries.fs2rx,
Dependencies.Libraries.fs2core,
Dependencies.Libraries.scalatest,
Dependencies.Libraries.ceTesting,
Dependencies.Libraries.scalactic
)
)
.dependsOn(ibCassandraModel)
lazy val root = project.in(file(".")).aggregate(ibCassandraModel, ibFeed)