-
Notifications
You must be signed in to change notification settings - Fork 21
/
build.gradle.kts
305 lines (263 loc) · 10.7 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
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.sonarsource.kotlin.buildsrc.tasks.CreateKotlinGradleRuleStubsTask
import org.sonarsource.kotlin.buildsrc.tasks.CreateKotlinRuleStubsTask
import org.sonarsource.kotlin.buildsrc.tasks.FetchRuleMetadata
plugins {
java
id("jacoco")
id("com.jfrog.artifactory") version "5.2.5"
id("org.sonarqube") version "5.1.0.4882"
id("org.jetbrains.kotlin.jvm") apply false
id("com.diffplug.spotless") version "6.11.0"
`maven-publish`
signing
}
val projectTitle: String by project
configure(subprojects.filter { it.name != "kotlin-checks-test-sources" }) {
apply(plugin = "com.diffplug.spotless")
configure<com.diffplug.gradle.spotless.SpotlessExtension> {
lineEndings = com.diffplug.spotless.LineEnding.UNIX
fun SourceSet.findSourceFilesToTarget() = allJava.srcDirs.flatMap { srcDir ->
project.fileTree(srcDir).filter { file ->
file.name.endsWith(".kt") || (file.name.endsWith(".java") && file.name != "package-info.java")
}
}
kotlin {
licenseHeaderFile(rootProject.file("LICENSE_HEADER")).updateYearWithLatest(true)
target(
project.sourceSets.main.get().findSourceFilesToTarget(),
project.sourceSets.test.get().findSourceFilesToTarget()
)
}
kotlinGradle {
target("*.gradle.kts")
ktlint()
}
format("misc") {
// define the files to apply `misc` to
target("*.gradle", "*.md", ".gitignore")
// define the steps to apply to those files
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
}
}
allprojects {
apply<JavaPlugin>()
apply(plugin = "jacoco")
apply(plugin = "com.jfrog.artifactory")
apply(plugin = "maven-publish")
apply(plugin = "signing")
gradle.projectsEvaluated {
tasks.withType<JavaCompile> {
if (project.hasProperty("warn")) {
options.compilerArgs = options.compilerArgs + "-Xlint:unchecked" + "-Xlint:deprecation"
} else {
options.compilerArgs = options.compilerArgs + "-Xlint:-unchecked" + "-Xlint:-deprecation"
}
}
}
val buildNumber: String? = System.getProperty("buildNumber")
ext {
set("buildNumber", buildNumber)
}
// Replaces the version defined in sources, usually x.y-SNAPSHOT, by a version identifying the build.
if (project.version.toString().endsWith("-SNAPSHOT") && buildNumber != null) {
val versionSuffix =
if (project.version.toString().count { it == '.' } == 1) ".0.$buildNumber" else ".$buildNumber"
project.version = project.version.toString().replace("-SNAPSHOT", versionSuffix)
}
repositories {
mavenCentral()
maven(url = "https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-ide-plugin-dependencies") {
content {
includeGroup("org.jetbrains.kotlin")
}
}
}
}
subprojects {
val javadoc: Javadoc by tasks
// do not publish to Artifactory by default
tasks.artifactoryPublish {
skip = true
}
java.sourceCompatibility = JavaVersion.VERSION_11
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
options.release.set(java.sourceCompatibility.majorVersion.toInt())
}
tasks.withType<KotlinCompile>().all {
compilerOptions.jvmTarget = JvmTarget.fromTarget(java.sourceCompatibility.toString())
}
jacoco {
toolVersion = "0.8.12"
}
tasks.jacocoTestReport {
reports {
xml.required.set(true)
csv.required.set(false)
html.required.set(false)
}
}
// when subproject has Jacoco pLugin applied we want to generate XML report for coverage
plugins.withType<JacocoPlugin> {
tasks["test"].finalizedBy("jacocoTestReport")
}
configurations {
// include compileOnly dependencies during test
testImplementation {
extendsFrom(configurations.compileOnly.get())
}
}
if (!project.path.startsWith(":its") && !project.path.startsWith(":private:its")) {
tasks.test {
useJUnitPlatform()
}
}
tasks.test {
testLogging {
exceptionFormat =
org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL // log the full stack trace (default is the 1st line of the stack trace)
events("skipped", "failed") // verbose log for failed and skipped tests (by default the name of the tests are not logged)
}
systemProperties = System.getProperties().filterKeys {
it is String &&
(it.startsWith("orchestrator") || it.startsWith("sonar") || it == "buildNumber" || it == "slangVersion")
}.mapKeys { it.key as String }
if (systemProperties.containsKey("buildNumber") && !systemProperties.containsKey("slangVersion")) {
systemProperties["slangVersion"] = version
}
}
val sourcesJar by tasks.creating(Jar::class) {
dependsOn(JavaPlugin.CLASSES_TASK_NAME)
archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
}
val javadocJar by tasks.creating(Jar::class) {
dependsOn(javadoc)
archiveClassifier.set("javadoc")
from(tasks["javadoc"])
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
pom {
name.set(projectTitle)
description.set(project.description)
url.set("http://www.sonarqube.org/")
organization {
name.set("SonarSource")
url.set("http://www.sonarqube.org/")
}
licenses {
license {
name.set("SSALv1")
url.set("https://sonarsource.com/license/ssal/")
distribution.set("repo")
}
}
scm {
url.set("https://github.com/SonarSource/sonar-kotlin")
}
developers {
developer {
id.set("sonarsource-team")
name.set("SonarSource Team")
}
}
}
}
}
}
signing {
val signingKeyId: String? by project
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
setRequired {
val branch = System.getenv()["CIRRUS_BRANCH"] ?: ""
(branch == "master" || branch.matches("branch-[\\d.]+".toRegex())) &&
gradle.taskGraph.hasTask(":artifactoryPublish")
}
sign(publishing.publications)
}
tasks.withType<Sign> {
onlyIf {
val branch = System.getenv()["CIRRUS_BRANCH"] ?: ""
val artifactorySkip: Boolean = tasks.artifactoryPublish.get().skip
!artifactorySkip && (branch == "master" || branch.matches("branch-[\\d.]+".toRegex())) &&
gradle.taskGraph.hasTask(":artifactoryPublish")
}
}
}
sonarqube {
properties {
property("sonar.links.ci", "https://cirrus-ci.com/github/SonarSource/sonar-kotlin")
property("sonar.projectName", projectTitle)
property("sonar.links.scm", "https://github.com/SonarSource/sonar-kotlin")
property("sonar.links.issue", "https://jira.sonarsource.com/browse/SONARKT")
property("sonar.exclusions", "**/build/**/*")
}
}
subprojects {
sonarqube.properties {
property(
"sonar.coverage.jacoco.xmlReportPaths",
listOf(
"build/reports/jacoco/test/jacocoTestReport.xml",
"${project.rootDir}/sonar-kotlin-plugin/build/reports/jacoco/testCodeCoverageReport/testCodeCoverageReport.xml"
).joinToString(",")
)
}
}
artifactory {
clientConfig.info.buildName = "sonar-kotlin"
clientConfig.info.buildNumber = System.getenv("BUILD_NUMBER")
clientConfig.isIncludeEnvVars = true
clientConfig.envVarsExcludePatterns =
"*password*,*PASSWORD*,*secret*,*MAVEN_CMD_LINE_ARGS*,sun.java.command,*token*,*TOKEN*,*LOGIN*,*login*,*key*,*KEY*,*PASSPHRASE*,*signing*"
// Define the artifacts to be deployed to https://binaries.sonarsource.com on releases
clientConfig.info.addEnvironmentProperty("ARTIFACTS_TO_PUBLISH", "${project.group}:sonar-kotlin-plugin:jar")
clientConfig.info.addEnvironmentProperty("ARTIFACTS_TO_DOWNLOAD", "")
// The name of this variable is important because it"s used by the delivery process when extracting version from Artifactory build info.
clientConfig.info.addEnvironmentProperty("PROJECT_VERSION", version.toString())
setContextUrl(System.getenv("ARTIFACTORY_URL"))
publish {
repository {
setRepoKey(System.getenv("ARTIFACTORY_DEPLOY_REPO"))
setUsername(System.getenv("ARTIFACTORY_DEPLOY_USERNAME"))
setPassword(System.getenv("ARTIFACTORY_DEPLOY_PASSWORD"))
}
defaults {
setProperties(
mapOf(
"build.name" to "sonar-kotlin",
"build.number" to System.getenv("BUILD_NUMBER"),
"pr.branch.target" to System.getenv("PULL_REQUEST_BRANCH_TARGET"),
"pr.number" to System.getenv("PULL_REQUEST_NUMBER"),
"vcs.branch" to System.getenv("GIT_BRANCH"),
"vcs.revision" to System.getenv("GIT_COMMIT"),
"version" to project.version as String,
)
)
publications("mavenJava")
setPublishPom(true) // Publish generated POM files to Artifactory (true by default)
setPublishIvy(false) // Publish generated Ivy descriptor files to Artifactory (true by default)
}
}
}
tasks.register<CreateKotlinRuleStubsTask>("setupRuleStubs") {
group = "Rules"
description = "Generate required stubs for a new Kotlin rule"
finalizedBy(tasks.findByPath(":generateRuleMetadata"))
}
tasks.register<CreateKotlinGradleRuleStubsTask>("setupGradleRuleStubs") {
group = "Rules"
description = "Generate required stubs for a new Kotlin Gradle DSL rule"
finalizedBy(tasks.findByPath(":generateRuleMetadata"))
}
tasks.register<FetchRuleMetadata.FetchSpecificRulesMetadata>("generateRuleMetadata")
tasks.register<FetchRuleMetadata.FetchAllRulesMetadata>("updateRuleMetadata")