-
Notifications
You must be signed in to change notification settings - Fork 20
/
build.gradle.kts
371 lines (327 loc) · 13.9 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
import org.gradle.api.JavaVersion.VERSION_17
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.util.Properties
import org.jetbrains.kotlin.incremental.createDirectory
group = "com.feysh.corax"
val pluginModules : String by project
val publishingModules : String by project
val kotlinVersion: String by project
val coroutinesVersion: String by project
val immutableCollectionsVersion: String by project
val pf4jVersion: String by project
val sootVersion: String by rootProject
val cpgVersion: String by rootProject
val junit4Version: String by project
val junit4PlatformVersion: String by project
val apacheCommonsLang3Version: String by rootProject
val kotlinLoggingVersion: String? by rootProject
val kotlinSerializationVersion: String by rootProject
val kamlVersion: String by rootProject
val guavaVersion: String by rootProject
val semVer: String? by project
val configDir by extra { file("${layout.buildDirectory.get()}/analysis-config") }
val pluginDir by extra { file("${layout.buildDirectory.get()}/analysis-config/plugins") }
version = semVer ?: "dev"
plugins {
`java-library`
kotlin("jvm") version "2.0.20"
kotlin("kapt") version "2.0.20"
kotlin("plugin.serialization") version "2.0.20"
`maven-publish`
// Gradle Properties Plugin - read more: https://github.com/stevesaliman/gradle-properties-plugin
id("net.saliman.properties") version "1.5.2"
id("com.github.johnrengelman.shadow") version "7.1.2"
}
buildscript {
repositories {
maven {
url = uri("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-serialization:2.0.20")
}
}
apply(plugin = "org.jetbrains.kotlin.plugin.serialization")
configure<JavaPluginExtension> {
sourceCompatibility = VERSION_17
targetCompatibility = VERSION_17
}
apply(from = "build.local.env.gradle.kts")
allprojects {
group = rootProject.group
version = rootProject.version
apply {
plugin("maven-publish")
plugin("kotlin")
}
tasks {
withType<JavaCompile> {
sourceCompatibility = "17"
targetCompatibility = "17"
options.encoding = "UTF-8"
options.compilerArgs = options.compilerArgs + "-Xlint:all"
options.isIncremental = true
}
withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "17"
freeCompilerArgs = freeCompilerArgs + listOf(
"-Xsam-conversions=class",
"-Xcontext-receivers"
)
allWarningsAsErrors = false
incremental = true
}
}
compileTestKotlin {
kotlinOptions {
freeCompilerArgs = freeCompilerArgs + listOf(
"-Xsam-conversions=class",
"-Xcontext-receivers"
)
allWarningsAsErrors = false
incremental = true
}
}
withType<Test> {
// set heap size for the test JVM(s)
minHeapSize = "128m"
maxHeapSize = "3072m"
jvmArgs = listOf("-XX:MaxHeapSize=3072m")
useJUnitPlatform {
excludeTags = setOf("slow", "IntegrationTest")
}
addTestListener(object : TestListener {
override fun beforeSuite(suite: TestDescriptor) {}
override fun beforeTest(testDescriptor: TestDescriptor) {}
override fun afterTest(testDescriptor: TestDescriptor, result: TestResult) {
println("[$testDescriptor.classDisplayName] [$testDescriptor.displayName]: $result.resultType, length - ${(result.endTime - result.startTime) / 1000.0} sec")
}
override fun afterSuite(testDescriptor: TestDescriptor, result: TestResult) {
if (testDescriptor.parent == null) { // will match the outermost suite
println("Test summary: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)")
}
}
})
// testLogging {
// events = setOf(TestLogEvent.STARTED,
// TestLogEvent.FAILED,
// TestLogEvent.SKIPPED,
// TestLogEvent.STANDARD_ERROR,
// // TestLogEvent.STANDARD_OUT,
// // TestLogEvent.PASSED
// )
// exceptionFormat = TestExceptionFormat.FULL
// showExceptions = true
// showCauses = true
// showStackTraces = true
// info.events = debug.events
// info.exceptionFormat = debug.exceptionFormat
// }
}
withType<Javadoc> {
isFailOnError=false
options.encoding = "UTF-8"
}
}
repositories {
mavenLocal()
maven("https://maven.aliyun.com/repository/central")
mavenCentral()
maven("https://s01.oss.sonatype.org/content/repositories/orgunittestbotsoot-1004/")
maven("https://plugins.gradle.org/m2")
maven("https://www.jetbrains.com/intellij-repository/releases")
maven("https://cache-redirector.jetbrains.com/maven-central")
}
dependencies {
testImplementation(group = "org.jetbrains.kotlin", name = "kotlin-stdlib-jdk8", version = kotlinVersion)
testImplementation(group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version = kotlinVersion)
testImplementation(group = "org.jetbrains.kotlin", name = "kotlin-reflect", version = kotlinVersion)
testImplementation(
group = "org.jetbrains.kotlinx",
name = "kotlinx-collections-immutable-jvm",
version = immutableCollectionsVersion
)
}
}
//subprojects {
// group = rootProject.group
// version = rootProject.version
//
// publishing {
// publications {
// create<MavenPublication>("jar") {
// from(components["java"])
// groupId = "com.feysh.corax"
// artifactId = project.name
// }
// }
// }
//}
dependencies {
implementation(group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version = kotlinVersion)
implementation(group = "org.jetbrains.kotlin", name = "kotlin-allopen", version = kotlinVersion)
}
configure(
pluginModules.split(",").map { project(":$it") }
) {
tasks.withType<KotlinCompile> {
//kotlinOptions.languageVersion = "1.8"
kotlinOptions.freeCompilerArgs += listOf(
"-XXLanguage:+ReferencesToSyntheticJavaProperties",
)
}
// if the variable definitions are put here they are resolved for each subproject
val pluginId: String by project
val pluginProvider: String by project
val pluginDependencies: String by project
apply {
plugin("net.saliman.properties")
plugin("com.github.johnrengelman.shadow")
plugin("org.jetbrains.kotlin.plugin.serialization")
plugin("org.jetbrains.kotlin.kapt")
}
dependencies{
compileOnly(group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-core-jvm", version = kotlinSerializationVersion)
compileOnly(group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-core", version = kotlinSerializationVersion)
compileOnly(group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = coroutinesVersion)
compileOnly(group = "org.jetbrains.kotlin", name = "kotlin-stdlib-jdk8", version = kotlinVersion)
compileOnly(group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version = kotlinVersion)
compileOnly(group = "org.jetbrains.kotlin", name = "kotlin-reflect", version = kotlinVersion)
compileOnly(group = "org.jetbrains.kotlin", name = "kotlin-bom", version = kotlinVersion)
compileOnly(group = "org.jetbrains.kotlinx", name = "kotlinx-collections-immutable-jvm", version = immutableCollectionsVersion)
compileOnly(sootVersion) { exclude(group="com.google.guava", module="guava") }
compileOnly(group = "de.fraunhofer.aisec", name = "cpg-core", version = cpgVersion) { exclude(group = "org.apache.logging.log4j") }
compileOnly(group = "de.fraunhofer.aisec", name = "cpg-language-java", version = cpgVersion) { exclude(group = "org.apache.logging.log4j") }
compileOnly(group = "com.charleskorn.kaml", name = "kaml", version = kamlVersion)
compileOnly(group = "io.github.microutils", name = "kotlin-logging", version = kotlinLoggingVersion)
compileOnly(group = "org.pf4j", name = "pf4j", version = pf4jVersion)
kapt(group = "org.pf4j", name = "pf4j", version = pf4jVersion)
testImplementation(sootVersion)
testImplementation(group = "de.fraunhofer.aisec", name = "cpg-core", version = cpgVersion) { exclude(group = "org.apache.logging.log4j") }
testImplementation(group = "de.fraunhofer.aisec", name = "cpg-language-java", version = cpgVersion) { exclude(group = "org.apache.logging.log4j") }
testImplementation(group = "org.pf4j", name = "pf4j", version = pf4jVersion)
testImplementation(group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version = coroutinesVersion)
testImplementation(group = "io.github.microutils", name = "kotlin-logging", version = kotlinLoggingVersion)
testImplementation(group = "org.apache.commons", name = "commons-lang3", version = apacheCommonsLang3Version)
testImplementation(group = "com.google.guava", name = "guava", version = guavaVersion)
testImplementation(group = "junit", name = "junit", version = junit4Version)
testImplementation(group = "org.junit.platform", name = "junit-platform-console-standalone", version = junit4PlatformVersion)
}
// for the jar task we have to set the plugin properties, so they can be written to the manifest
tasks.named<Jar>("jar") {
manifest {
attributes["Plugin-Id"] = pluginId
attributes["Plugin-Version"] = archiveVersion
attributes["Plugin-Provider"] = pluginProvider
if (pluginDependencies.isNotEmpty()) {
attributes["Plugin-Dependencies"] = pluginDependencies
}
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
val pluginZip = tasks.register<Zip>("plugin") {
archiveBaseName.set("${pluginId}-plugin")
// first taking the classes generated by the jar task
into("classes") {
val jarTask = tasks.named<Jar>("jar").get()
val jarFile = jarTask.archiveFile.get().asFile
from(zipTree(jarFile).matching {
include("META-INF/**")
})
}
// and then we also need to include any libraries that are needed by the plugin
dependsOn(configurations.runtimeClasspath)
into("lib") {
from(tasks.named<Jar>("jar").get())
from({
configurations.runtimeClasspath.get()
.filter { it.name.endsWith("jar") }
.filter{ !it.name.startsWith("kotlin-stdlib") }
.filter{ !it.name.startsWith("kotlinx-serialization-core-jvm") }
.filter{ !it.name.startsWith("kotlinx-serialization-json-jvm") }
})
}
archiveExtension.set("zip")
isZip64 = true
}
tasks.register<Copy>("copyRules") {
dependsOn(pluginZip)
val fromConfigsDir = projectDir.resolve("rules")
val toConfigDir = configDir.resolve("rules")
if (fromConfigsDir.exists()) {
from(fromConfigsDir)
into(toConfigDir)
doFirst {
println("copy $fromConfigsDir to $toConfigDir")
}
}
}
// the assemblePlugin will copy the zip file into the common plugins directory
tasks.register<Copy>("copyPlugin") {
dependsOn("copyRules")
dependsOn(pluginZip)
from(pluginZip)
into(pluginDir)
val archiveFileName = pluginZip.get().archiveFileName.get()
val folder = archiveFileName.substringBeforeLast(pluginZip.get().archiveExtension.get()).dropLast(1)
val extract = "$pluginDir/${folder}"
doFirst {
println("delete $extract")
delete(extract)
delete("$configDir/default-config.yml")
delete("$configDir/default-config.normalize.yml")
}
}
tasks.register("createProperties") {
dependsOn("processResources")
dependsOn("processTestResources")
doLast {
val file = File("${layout.buildDirectory.get()}/resources/test/project.properties")
file.parentFile.takeIf { !it.exists() }?.createDirectory()
val engineJar: File? by rootProject.extra
file.bufferedWriter().use { writer ->
val properties = Properties()
properties["engineJar"] = engineJar?.path ?: ""
properties.store(writer, null)
}
}
}
tasks {
"testClasses" {
dependsOn(named("createProperties"))
}
"classes" {
dependsOn(named("createProperties"))
}
"build" {
dependsOn(named("createProperties"))
dependsOn(named("plugin"))
dependsOn(named("copyPlugin"))
}
}
}
configure(
publishingModules.split(",").map { project(":$it") }
) {
publishing {
publications {
create<MavenPublication>("library") {
from(components["java"])
}
}
}
}
subprojects {
tasks.test {
useJUnitPlatform()
testLogging {
showStandardStreams = true
showCauses = true
showExceptions = true
setExceptionFormat("full")
setEvents(setOf("passed", "skipped", "failed", "standardOut", "standardError"))
}
}
}