This repository has been archived by the owner on Jun 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle.kts
169 lines (149 loc) · 5.54 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
import org.cqfn.diktat.plugin.gradle.DiktatJavaExecTaskBase
import org.springframework.boot.gradle.tasks.bundling.BootJar
import org.springframework.boot.gradle.tasks.run.BootRun
plugins {
id("com.github.ben-manes.versions") version "0.42.0"
java
`maven-publish`
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.kotlin.spring)
alias(libs.plugins.spring.boot)
alias(libs.plugins.diktat)
id("com.palantir.git-version") version "0.15.0" apply (System.getenv("SOURCE_VERSION") == null)
}
publishing {
publications {
create<MavenPublication>("maven") {
groupId = "ord.cqfn.diktat"
version = project.version as String
description = "diktat-demo"
from(components["java"])
}
}
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
val diktatVersion = libs.versions.diktat.get()
val ktlintVersion = libs.versions.ktlint.get()
kotlin {
js(LEGACY).browser {
repositories {
mavenCentral()
}
}
jvm {
repositories {
mavenCentral()
maven("https://repo.spring.io/milestone")
}
withJava()
compilations.all {
kotlinOptions {
jvmTarget = "11"
}
}
}
sourceSets {
getByName("commonMain") {
dependencies {
implementation(libs.kotlinx.serialization.json)
}
}
getByName("jvmMain") {
dependencies {
implementation(libs.spring.boot.starter.web)
implementation(libs.spring.fu.kofu)
// todo: kotlin plugin 1.5.20 doesn't support dependencies on `Provider<MinimalExternalModuleDependency>` with configuration lambda
implementation("org.cqfn.diktat:diktat-common:$diktatVersion") {
// exclude to use logback provided by spring
exclude(group = "org.apache.logging.log4j")
}
implementation("org.cqfn.diktat:diktat-rules:$diktatVersion") {
exclude(group = "org.apache.logging.log4j")
}
implementation(libs.ktlint.core)
implementation(libs.ktlint.rulesets.standard)
}
}
getByName("jvmTest") {
dependencies {
implementation(libs.spring.boot.starter.test)
}
}
getByName("jsMain") {
dependencies {
implementation(libs.kotlin.js.react)
implementation(libs.kotlin.js.reactDom)
implementation(npm("ace-builds", "1.4.11"))
implementation(npm("jquery", "1.12.4"))
implementation(npm("react", libs.versions.react.get()))
implementation(npm("react-dom", libs.versions.react.get()))
implementation(libs.kotlinx.coroutines.core)
}
}
}
}
val generateVersionFileTaskProvider = tasks.register("generateVersionFile") {
val versionsFile = File("$buildDir/generated/src/generated/Versions.kt")
// heroku sets `SOURCE_VERSION` variable during build, while git repo is unavailable
// for successful build either .git directory should be present or SOURCE_VERSION should be set
val gitRevision = System.getenv("SOURCE_VERSION")
?: (ext.properties["gitVersion"] as groovy.lang.Closure<String>).invoke()
inputs.property("project version", version.toString())
inputs.property("project revision", gitRevision)
inputs.property("diktat version", diktatVersion)
inputs.property("ktlint version", ktlintVersion)
outputs.file(versionsFile)
doFirst {
versionsFile.parentFile.mkdirs()
versionsFile.writeText(
"""
package generated
internal const val PROJECT_VERSION = "$version"
internal const val PROJECT_REVISION = "$gitRevision"
internal const val DIKTAT_VERSION = "$diktatVersion"
internal const val KTLINT_VERSION = "$ktlintVersion"
""".trimIndent()
)
}
}
val generatedKotlinSrc = kotlin.sourceSets.create("generated") {
kotlin.srcDir("$buildDir/generated/src")
}
kotlin.sourceSets.getByName("jsMain").dependsOn(generatedKotlinSrc)
tasks.withType<org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile>().forEach {
it.dependsOn(generateVersionFileTaskProvider)
}
tasks.getByName("jvmMainClasses") {
dependsOn(tasks.getByName("jsBrowserProductionWebpack"))
doLast {
mkdir("build/processedResources/jvm/main/static")
copy {
from("$buildDir/distributions")
into("build/processedResources/jvm/main/static")
}
}
}
tasks.getByName<Copy>("jvmProcessResources") {
// workaround for gradle >= 7, because some bug with kotlin plugin's `withJava` setting, at least for 1.5.20
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
tasks.getByName<BootJar>("bootJar") {
mainClass.set("com.saveourtool.diktat.demo.DiktatDemoApplicationKt")
requiresUnpack("**/kotlin-compiler-embeddable-*.jar")
}
tasks.getByName<BootRun>("bootRun") {
mainClass.set("com.saveourtool.diktat.demo.DiktatDemoApplicationKt")
}
diktat {
githubActions = findProperty("diktat.githubActions")?.toString()?.toBoolean() ?: false
inputs {
include("src/*/kotlin/**/*.kt")
}
tasks.withType<DiktatJavaExecTaskBase>().configureEach {
// https://github.com/analysis-dev/diktat/issues/1269
systemProperty("user.home", rootDir.toString())
}
}