-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.gradle
153 lines (118 loc) · 4.55 KB
/
common.gradle
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
// overrides default "build"
buildDir file("target")
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
project.ext {
scalaVersion = hasProperty("scalaVersion") ? scalaVersion : "3.3.4"
isLocalInstall = hasProperty("scalaLocalInstall") ? scalaLocalInstall.toBoolean() : false
isScala3 = scalaVersion.startsWith("3")
scalacMainClass = isScala3 ? "dotty.tools.dotc.Main": "scala.tools.nsc.Main"
repositories {
mavenCentral()
maven {
// https://doc.akka.io/docs/akka/current/typed/actors.html
url "https://repo.akka.io/maven"
}
}
scalaBinaryVersion = isScala3 ? "3" : "2.13"
// https://mvnrepository.com/artifact/com.typesafe.akka/akka-actor
// https://mvnrepository.com/artifact/ch.qos.logback/logback-classic
// https://mvnrepository.com/artifact/org.scalatest/scalatest
// https://mvnrepository.com/artifact/org.scalatest/scalatest-core
// https://mvnrepository.com/artifact/org.specs2/specs2-core
akkaVersion = "2.10.0"
configVersion = "1.4.3"
logbackVersion = "1.5.12"
specs2Version = isScala3 ? "5.5.8" : "4.20.9"
dependencies {
if (isScala3) {
implementation "org.scala-lang:scala3-compiler_3:$scalaVersion"
}
else {
implementation "org.scala-lang:scala-compiler:$scalaVersion"
}
implementation "com.typesafe:config:$configVersion"
implementation "com.typesafe.akka:akka-actor_${scalaBinaryVersion}:$akkaVersion"
// test scope
testImplementation 'ch.qos.logback:logback-classic:$logbackVersion'
testImplementation "com.typesafe.akka:akka-testkit_${scalaBinaryVersion}:$akkaVersion"
testImplementation 'junit:junit:4.13.2'
testImplementation "org.specs2:specs2-junit_${scalaBinaryVersion}:$specs2Version"
}
mainSourceTree = fileTree(dir: "src/main/scala", include: "**/*.scala")
testSourceTree = fileTree(dir: "src/test/scala", include: "**/*.scala")
classesDir = file("${buildDir}/classes")
testClassesDir = file("${buildDir}/test-classes")
if (isLocalInstall) {
scalaHome = System.getenv(isScala3 ? "SCALA3_HOME" : "SCALA_HOME")
logger.info("scalaHome = $scalaHome")
libraryPath = file(scalaHome + "/lib")
libraryFiles = files { libraryPath.listFiles() }
libraryFiles = libraryFiles.filter { File f -> f.name.matches("(.*)\\.jar") }
toolClasspath = files(libraryFiles)
} else {
toolClasspath = files()
}
buildClasspath = files(toolClasspath, sourceSets.main.runtimeClasspath, classesDir)
testClasspath = files(buildClasspath, testClassesDir)
logger.info("scalacMainClass = $scalacMainClass")
logger.info("buildClasspath = ${buildClasspath.getAsPath()}")
logger.info("testClasspath = ${testClasspath.getAsPath()}")
}
clean.doLast {
buildDir.deleteDir()
}
tasks.withType(JavaCompile) {
// https://docs.gradle.org/current/dsl/org.gradle.api.tasks.compile.CompileOptions.html
options.deprecation true
options.encoding "UTF8"
}
task compileScala(type: JavaExec) {
dependsOn compileJava
description "Compile Scala source files"
classpath = buildClasspath
jvmArgs "-Dscala.usejavacp=true"
mainClass = scalacMainClass
String sourceFiles = mainSourceTree.files.join("\" \"").replaceAll("\\\\", "/")
args "-deprecation", "-encoding", "UTF8", "-d", classesDir, sourceFiles
}
compileScala.doFirst {
if (!classesDir.exists()) classesDir.mkdirs()
}
compileScala.onlyIf {
! mainSourceTree.isEmpty()
}
build {
dependsOn compileScala
}
task run(type: JavaExec) {
dependsOn build
description "Execute Scala main class $mainClassName"
classpath = buildClasspath
jvmArgs "-Xms1024m", "-Xss2m", "-Dfile.encoding=UTF-8"
// systemProperty "message" "Hello"
if (mainClassName?.trim()) mainClass = mainClassName
else mainClass = "Main"
if (args == null) args ""
}
task compileTest(type: JavaExec) {
dependsOn compileScala
description "Compile Scala test source files"
classpath = testClasspath
jvmArgs "-Dscala.usejavacp=true"
mainClass = scalacMainClass
String sourceFiles = testSourceTree.files.join("\" \"").replaceAll("\\\\", "/")
args "-deprecation", "-encoding", "UTF8", "-d", testClassesDir, sourceFiles
}
compileTest.doFirst {
if (!testClassesDir.exists()) testClassesDir.mkdirs()
}
compileTest.onlyIf {
! testSourceTree.isEmpty()
}
test {
dependsOn compileTest
println "test: not yet implemented"
}