/
build.gradle.kts
209 lines (174 loc) · 8.59 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
import com.virtuslab.gitmachete.buildsrc.*
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import java.util.Base64
plugins {
checkstyle
`java-library`
scala
alias(libs.plugins.taskTree)
}
fun getFlagsForAddExports(vararg packages: String, module: String): List<String> {
return packages.toList().map { "--add-exports=$module/$it=ALL-UNNAMED" }
}
val targetJavaVersion: JavaVersion by extra(JavaVersion.VERSION_17)
val ciBranch: String? by extra(System.getenv("CIRCLE_BRANCH"))
val isCI: Boolean by extra(System.getenv("CI") == "true")
val jetbrainsMarketplaceToken: String? by extra(System.getenv("JETBRAINS_MARKETPLACE_TOKEN"))
val intellijVersions by extra(
IntellijVersions.from(
intellijVersionsProperties = PropertiesHelper.getProperties(rootDir.resolve("intellij-versions.properties")),
overrideBuildTarget = project.properties["overrideBuildTarget"] as String?,
),
)
fun String.fromBase64(): String {
return String(Base64.getDecoder().decode(this))
}
val pluginSignCertificateChain: String? by extra(System.getenv("PLUGIN_SIGN_CERT_CHAIN_BASE64")?.fromBase64())
val pluginSignPrivateKey: String? by extra(System.getenv("PLUGIN_SIGN_PRIVATE_KEY_BASE64")?.fromBase64())
val pluginSignPrivateKeyPass: String? by extra(System.getenv("PLUGIN_SIGN_PRIVATE_KEY_PASS"))
val compileJavaJvmArgs: List<String>? by extra((project.properties["compileJavaJvmArgs"] as String?)?.split(" "))
val shouldRunAllCheckers: Boolean by extra(isCI || project.hasProperty("runAllCheckers"))
tasks.register<UpdateIntellijVersions>("updateIntellijVersions")
val configCheckerDirectory: String by extra(rootProject.file("config/checker").path)
allprojects {
repositories {
mavenLocal()
mavenCentral()
}
apply<JavaLibraryPlugin>()
java {
sourceCompatibility = targetJavaVersion
targetCompatibility = targetJavaVersion // redundant, added for clarity
}
// String interpolation support, see https://github.com/antkorwin/better-strings.
// This needs to be enabled in each subproject by default because there's going to be no warning
// if this annotation processor isn't run in any subproject (the strings will be just interpreted
// verbatim, without interpolation applied).
// Otherwise, we'd only capture an unprocessed interpolation in ArchUnit tests by analyzing constant pools of classes.
betterStrings()
tasks.withType<JavaCompile> {
options.compilerArgs.addAll(
listOf(
// Enforce explicit `.toString()` call in code generated for string interpolations
"-AcallToStringExplicitlyInInterpolations",
// Treat each compiler warning (esp. the ones coming from Checker Framework) as an error.
"-Werror",
// Warn of type-unsafe operations on generics.
"-Xlint:unchecked",
),
)
options.isFork = true
options.forkOptions.jvmArgs?.addAll(
compileJavaJvmArgs
?: (if (isCI) listOf() else listOf("-Xmx6G", "-XX:+HeapDumpOnOutOfMemoryError")),
)
// Required for better-strings to work under Java 17: https://github.com/antkorwin/better-strings/issues/21
options.forkOptions.jvmArgs?.addAll(
getFlagsForAddExports(
"com.sun.tools.javac.api",
"com.sun.tools.javac.code",
"com.sun.tools.javac.processing",
"com.sun.tools.javac.tree",
"com.sun.tools.javac.util",
module = "jdk.compiler",
),
)
// `sourceCompatibility` and `targetCompatibility` say nothing about the Java APIs available to the compiled code.
// In fact, for X < Y it's perfectly possible to compile Java X code that uses Java Y APIs...
// This will work fine, until we actually try to run those compiled classes under Java X-compatible JVM,
// when we'll end up with NoSuchMethodError for APIs added between Java X and Java Y
// (i.e. for X=8 and Y=11: InputStream#readAllBytes, Stream#takeWhile and String#isBlank).
// `options.release = X` makes sure that regardless of Java version used to run the compiler,
// only Java X-compatible APIs are available to the compiled code.
options.release.set(Integer.parseInt(targetJavaVersion.majorVersion))
// Add files from config/checker directory as inputs to java compilation (so that changes trigger recompilation).
// These files are config files for the Checker Framework, which is for Java exclusively.
inputs.dir(configCheckerDirectory)
}
tasks.withType<Javadoc> {
// See JDK-8200363 (https://bugs.openjdk.java.net/browse/JDK-8200363) for information about the `-Xwerror` option:
// this is needed to make sure that javadoc always fails on warnings
// (esp. important on CI since javadoc there for some reason seems to never raise any errors otherwise).
// The '-quiet' as second argument is actually a hack around
// https://github.com/gradle/gradle/issues/2354:
// since the one-parameter `addStringOption` doesn't seem to work, we need to add an extra
// `-quiet`, which is added anyway by Gradle.
(options as StandardJavadocDocletOptions).addStringOption("Xwerror", "-quiet")
// Suppress `doclint` for `missing`; otherwise javadoc for every member would be required.
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:all,-missing", "-quiet")
options.quiet()
}
tasks.withType<Test> {
useJUnitPlatform()
if (project.properties["forceRunTests"] != null) {
outputs.upToDateWhen { false }
}
testLogging {
if (project.properties["printTestOutput"] != null) {
showStandardStreams = true
}
exceptionFormat = TestExceptionFormat.FULL
showCauses = true
showExceptions = true
showStackTraces = true
}
}
configureCheckerFramework()
configureCheckstyle()
configureSpotless()
// A few libraries (like JGit) transitively pull in a version of slf4j-api
// that might be different from the slf4j-api version that IntelliJ depends on.
// SLF4J guarantees that the code compiled against a certain slf4j-api version will work with any
// other version of slf4j-api (http://www.slf4j.org/manual.html#compatibility).
// We rely on that guarantee: our plugin effectively uses whatever slf4j-api version is provided by IntelliJ.
// SLF4J does NOT guarantee, however, that slf4j-api version X will work with any slf4j
// implementation version Y for X != Y.
// To avoid a clash between JGit&co.'s slf4j-api and Intellij's slf4j implementation
// (and also between JGit&co.'s slf4j-api and Intellij's slf4j-api), we need to exclude the former
// from ALL dependencies.
configurations.runtimeClasspath { exclude(group = "org.slf4j", module = "slf4j-api") }
}
subprojects {
// This is necessary to make sure that `buildPlugin` task puts jars of all relevant subprojects
// into the final zip.
// No need to include near-empty (only with META-INF/MANIFEST.MF) jars
// for subprojects that don't have any production code.
if (sourceSets["main"].allSource.srcDirs.any { it?.exists() == true }) {
rootProject.dependencies { implementation(project) }
}
// By default, the jar name will be formed only from the last segment of subproject path.
// Since these last segments are NOT unique (there are many `api`s and `impl`s),
// the effective jar name will be something like api.jar, api_1.jar, api_2.jar etc.,
// which is suboptimal.
// Let's use full name like frontend-ui-api.jar instead.
base.archivesName.set(path.replaceFirst(":", "").replace(":", "-"))
}
// Root project config
group = "com.virtuslab"
configureVersionFromGit()
configureIntellijPlugin()
val uiTest = sourceSets.create("uiTest")
val uiTestImplementation: Configuration by configurations.getting { extendsFrom(configurations.testImplementation.get()) }
// This configuration apparently needs to be defined explicitly (despite not being used explicitly anywhere)
// so that UI test runtime classpath inherits `testRuntimeOnly` dependencies of the root project.
val uiTestRuntimeOnly: Configuration by configurations.getting { extendsFrom(configurations.testRuntimeOnly.get()) }
configureUiTests()
dependencies {
uiTestImplementation(testFixtures(project(":testCommon")))
// implementation("org.scala-lang:scala-library:2.13.10") // uncomment in case of IntelliJ loading error
}
applyKotlinConfig()
archunit()
// Checker is needed in root project runtime (not just compile-time) classpath for ArchUnit tests
checkerQual("test")
ideProbe()
jgit("test")
junit()
junitPlatformLauncher()
lombok("test")
vavr("test")
// This is needed solely for ArchUnit tests that detect unprocessed string interpolations
// to access constant pools of classes.
tasks.withType<Test> {
jvmArgs(getFlagsForAddExports("jdk.internal.reflect", module = "java.base"))
}