-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle.kts
186 lines (152 loc) · 5.76 KB
/
build.gradle.kts
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
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
group = "jetbrains.kotlin.course"
version = "0.0.1-SNAPSHOT"
fun properties(key: String) = project.findProperty(key).toString()
@Suppress("DSL_SCOPE_VIOLATION") // "libs" produces a false-positive warning, see https://youtrack.jetbrains.com/issue/KTIJ-19369
plugins {
java
val kotlinVersion = "2.0.0"
id("org.jetbrains.kotlin.jvm") version kotlinVersion apply false
id("org.jetbrains.kotlin.multiplatform") version kotlinVersion apply false
id("org.springframework.boot") version "2.7.3" apply false
id("io.spring.dependency-management") version "1.0.13.RELEASE" apply false
id("org.jetbrains.kotlin.plugin.spring") version kotlinVersion apply false
id("org.siouan.frontend-jdk11") version "6.0.0"
}
allprojects {
repositories {
mavenCentral()
maven {
url = uri("https://packages.jetbrains.team/maven/p/kotlin-test-framework/kotlin-test-framework")
}
}
}
tasks {
wrapper {
gradleVersion = properties("gradleVersion")
}
}
val frontendSuffix = "Frontend"
val server = "Server"
configure(subprojects.filter { frontendSuffix !in it.name }) {
apply {
plugin("java")
plugin("kotlin")
}
dependencies {
implementation("org.jetbrains.academy.test.system:core:2.0.7")
}
val jvmVersion = "11"
tasks {
withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = jvmVersion
}
}
withType<JavaCompile> {
sourceCompatibility = jvmVersion
targetCompatibility = jvmVersion
}
withType<Test> {
useJUnitPlatform()
outputs.upToDateWhen { false }
addTestListener(object : TestListener {
override fun beforeSuite(suite: TestDescriptor) {}
override fun beforeTest(testDescriptor: TestDescriptor) {}
override fun afterTest(testDescriptor: TestDescriptor, result: TestResult) {
if (result.resultType == TestResult.ResultType.FAILURE) {
val message = result.exception?.message ?: "Wrong answer"
val lines = message.split("\n")
println("#educational_plugin FAILED + ${lines[0]}")
lines.subList(1, lines.size).forEach { line ->
println("#educational_plugin$line")
}
// we need this to separate output of different tests
println()
}
}
override fun afterSuite(suite: TestDescriptor, result: TestResult) {}
})
}
}
}
fun String.getGameName(suffix: String) = substring(0 until indexOf(suffix))
configure(subprojects.filter { server in it.name || "utils" in it.name }) {
apply {
plugin("java")
plugin("kotlin")
}
dependencies {
val junitJupiterVersion = "5.9.0"
implementation("org.junit.jupiter:junit-jupiter-api:$junitJupiterVersion")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion")
testImplementation("org.junit.jupiter:junit-jupiter-params:$junitJupiterVersion")
testRuntimeOnly("org.junit.platform:junit-platform-console:1.9.0")
}
}
configure(subprojects.filter { server in it.name }) {
val projectName = this.name
val gameName = projectName.getGameName(server)
apply {
plugin("java")
plugin("kotlin")
plugin("org.springframework.boot")
plugin("io.spring.dependency-management")
plugin("org.jetbrains.kotlin.plugin.spring")
}
dependencies {
implementation(project(":utils"))
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.7.10")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.14.1")
}
// tasks.named("processResources") {
// dependsOn(":$gameName$frontendSuffix:build")
// }
sourceSets {
getByName("main").java.srcDirs("$gameName/src/main/kotlin")
getByName("main").resources.srcDirs("$gameName/src/main/resources")
getByName("test").java.srcDirs("test")
}
tasks.register<Exec>("run") {
// Just do nothing to avoid the edu plugin errors
}
}
configure(subprojects.filter { frontendSuffix in it.name }) {
val projectName = this.name
val gameName = projectName.getGameName(frontendSuffix)
apply {
plugin("org.siouan.frontend-jdk11")
}
frontend {
nodeDistributionProvided.set(false)
nodeVersion.set("16.17.1")
yarnEnabled.set(true)
yarnVersion.set("3.0.0")
installScript.set("install")
}
val yarnRunBuildTask = tasks.register<Exec>("yarnRunBuildTask") {
commandLine("yarn", "run", "build")
}
val serveResourcesTask = tasks.register("serveResources") {
dependsOn(yarnRunBuildTask)
val serverResources = rootProject.subprojects
.filter { gameName in it.name && server in it.name }
// the project name looks like: gameName-moduleName
.map { "$rootDir/$gameName$server/${it.name.split('-').last()}/src/main/resources/static/" }
val staticFolder = "$rootDir/$gameName$frontendSuffix/build"
doLast {
serverResources.forEach { resourcesPath ->
rootProject.delete(resourcesPath)
copy {
from(staticFolder)
into(resourcesPath)
}
}
}
}
serveResourcesTask {
mustRunAfter(":$gameName$frontendSuffix:${yarnRunBuildTask.name}")
}
}