This repository was archived by the owner on Apr 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sbt
187 lines (169 loc) · 7.53 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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import java.util.Properties
import com.itv.scalapact.plugin._
val Scalaversion = "2.13.3"
val Scalatraversion = "2.8.2"
val ScalaLoggingVersion = "3.9.2"
val ScalaTestVersion = "3.2.1"
val Log4JVersion = "2.17.0"
val Jettyversion = "9.4.35.v20201120"
val AwsSdkversion = "1.11.658"
val MockitoVersion = "1.14.8"
val Elastic4sVersion = "6.7.8"
val JacksonVersion = "2.12.1"
val ElasticsearchVersion = "6.8.13"
val Json4SVersion = "4.0.3"
val FlywayVersion = "7.1.1"
val PostgresVersion = "42.2.14"
val HikariConnectionPoolVersion = "3.4.5"
val appProperties = settingKey[Properties]("The application properties")
appProperties := {
val prop = new Properties()
IO.load(prop, new File("build.properties"))
prop
}
lazy val commonSettings = Seq(
organization := appProperties.value.getProperty("NDLAOrganization"),
version := appProperties.value.getProperty("NDLAComponentVersion"),
scalaVersion := Scalaversion
)
val pactVersion = "2.3.16"
val pactTestFramework = Seq(
"com.itv" %% "scalapact-circe-0-13" % pactVersion % "test",
"com.itv" %% "scalapact-http4s-0-21" % pactVersion % "test",
"com.itv" %% "scalapact-scalatest" % pactVersion % "test"
)
// Sometimes we override transitive dependencies because of vulnerabilities, we put these here
val vulnerabilityOverrides = Seq(
"com.google.guava" % "guava" % "30.0-jre",
"commons-codec" % "commons-codec" % "1.14",
"org.yaml" % "snakeyaml" % "1.26",
"com.fasterxml.jackson.core" % "jackson-core" % JacksonVersion,
"com.fasterxml.jackson.core" % "jackson-databind" % JacksonVersion,
"com.fasterxml.jackson.module" %% "jackson-module-scala" % JacksonVersion,
"org.apache.httpcomponents" % "httpclient" % "4.5.13"
)
lazy val PactTest = config("pact") extend Test
lazy val article_api = (project in file("."))
.configs(PactTest)
.settings(
inConfig(PactTest)(Defaults.testTasks),
// Since pactTest gets its options from Test configuration, the 'Test' (default) config won't run PactProviderTests
// To run all tests use pact config ('sbt pact:test')
Test / testOptions := Seq(Tests.Argument("-l", "PactProviderTest")),
PactTest / testOptions := Seq.empty
)
.settings(commonSettings: _*)
.settings(
name := "article-api",
javacOptions ++= Seq("-source", "1.8", "-target", "1.8"),
scalacOptions := Seq("-target:jvm-1.8", "-unchecked", "-deprecation", "-feature"),
libraryDependencies ++= Seq(
"ndla" %% "language" % "1.0.0",
"ndla" %% "mapping" % "0.15",
"ndla" %% "network" % "0.47",
"ndla" %% "validation" % "0.55",
"ndla" %% "scalatestsuite" % "0.3" % "test",
"joda-time" % "joda-time" % "2.10",
"org.scalatra" %% "scalatra" % Scalatraversion,
"org.eclipse.jetty" % "jetty-webapp" % Jettyversion % "container;compile",
"org.eclipse.jetty" % "jetty-plus" % Jettyversion % "container",
"javax.servlet" % "javax.servlet-api" % "4.0.1" % "container;provided;test",
"org.scalatra" %% "scalatra-json" % Scalatraversion,
"org.scalatra" %% "scalatra-scalatest" % Scalatraversion % "test",
"org.json4s" %% "json4s-native" % Json4SVersion,
"org.scalatra" %% "scalatra-swagger" % Scalatraversion,
"com.typesafe.scala-logging" %% "scala-logging" % ScalaLoggingVersion,
"org.apache.logging.log4j" % "log4j-api" % Log4JVersion,
"org.apache.logging.log4j" % "log4j-core" % Log4JVersion,
"org.apache.logging.log4j" % "log4j-slf4j-impl" % Log4JVersion,
"org.scalikejdbc" %% "scalikejdbc" % "4.0.0-RC2",
"org.postgresql" % "postgresql" % PostgresVersion,
"com.zaxxer" % "HikariCP" % HikariConnectionPoolVersion,
"com.amazonaws" % "aws-java-sdk-s3" % AwsSdkversion,
"com.amazonaws" % "aws-java-sdk-cloudwatch" % AwsSdkversion,
"org.scalaj" %% "scalaj-http" % "2.4.2",
"org.elasticsearch" % "elasticsearch" % ElasticsearchVersion,
"com.sksamuel.elastic4s" %% "elastic4s-core" % Elastic4sVersion,
"com.sksamuel.elastic4s" %% "elastic4s-http" % Elastic4sVersion,
"vc.inreach.aws" % "aws-signing-request-interceptor" % "0.0.22",
"org.scalatest" %% "scalatest" % ScalaTestVersion % "test",
"org.jsoup" % "jsoup" % "1.11.3",
"net.bull.javamelody" % "javamelody-core" % "1.74.0",
"org.jrobin" % "jrobin" % "1.5.9", // This is needed for javamelody graphing
"org.mockito" %% "mockito-scala" % MockitoVersion % "test",
"org.mockito" %% "mockito-scala-scalatest" % MockitoVersion % "test",
"org.flywaydb" % "flyway-core" % FlywayVersion,
"io.lemonlabs" %% "scala-uri" % "1.5.1"
) ++ pactTestFramework ++ vulnerabilityOverrides
)
.enablePlugins(ScalaTsiPlugin)
.settings(
// The classes that you want to generate typescript interfaces for
typescriptGenerationImports := Seq("no.ndla.articleapi.model.api._",
"no.ndla.articleapi.model.api.TSTypes._",
"no.ndla.articleapi.model.domain.Availability"),
typescriptExports := Seq(
"ArticleV2",
"ArticleSearchParams",
"ArticleSummaryV2",
"PartialPublishArticle",
"Availability.type",
"SearchResultV2",
"TagsSearchResult",
"ArticleDump",
"ValidationError"
),
typescriptOutputFile := baseDirectory.value / "typescript" / "index.ts",
)
.enablePlugins(DockerPlugin)
.enablePlugins(JettyPlugin)
.enablePlugins(ScalaPactPlugin)
assembly / assemblyJarName := "article-api.jar"
assembly / mainClass := Some("no.ndla.articleapi.JettyLauncher")
assembly / assemblyMergeStrategy := {
case "module-info.class" => MergeStrategy.discard
case x if x.endsWith("/module-info.class") => MergeStrategy.discard
case "mime.types" => MergeStrategy.filterDistinctLines
case PathList("org", "joda", "convert", "ToString.class") => MergeStrategy.first
case PathList("org", "joda", "convert", "FromString.class") => MergeStrategy.first
case PathList("org", "joda", "time", "base", "BaseDateTime.class") => MergeStrategy.first
case x =>
val oldStrategy = (assembly / assemblyMergeStrategy).value
oldStrategy(x)
}
val checkfmt = taskKey[Boolean]("check for code style errors")
checkfmt := {
val noErrorsInMainFiles = (Compile / scalafmtCheck).value
val noErrorsInTestFiles = (Test / scalafmtCheck).value
val noErrorsInBuildFiles = (Compile / scalafmtSbtCheck).value
noErrorsInMainFiles && noErrorsInTestFiles && noErrorsInBuildFiles
}
Test / test := (Test / test).dependsOn(Test / checkfmt).value
val fmt = taskKey[Unit]("Automatically apply code style fixes")
fmt := {
(Compile / scalafmt).value
(Test / scalafmt).value
(Compile / scalafmtSbt).value
}
// Make the docker task depend on the assembly task, which generates a fat JAR file
docker := (docker dependsOn assembly).value
docker / dockerfile := {
val artifact = (assembly / assemblyOutputPath).value
val artifactTargetPath = s"/app/${artifact.name}"
new Dockerfile {
from("adoptopenjdk/openjdk11:alpine-slim")
run("apk", "--no-cache", "add", "ttf-dejavu")
add(artifact, artifactTargetPath)
entryPoint("java", "-Dorg.scalatra.environment=production", "-jar", artifactTargetPath)
}
}
docker / imageNames := Seq(
ImageName(namespace = Some(organization.value),
repository = name.value,
tag = Some(System.getProperty("docker.tag", "SNAPSHOT")))
)
Test / parallelExecution := false
resolvers ++= scala.util.Properties
.envOrNone("NDLA_RELEASES")
.map(repo => "Release Sonatype Nexus Repository Manager" at repo)
.toSeq