-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.gradle
154 lines (128 loc) · 4.04 KB
/
common.gradle
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
// overrides default "build"
buildDir file("target")
java {
sourceCompatibility = JavaVersion.VERSION_17 // JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_17 // JavaVersion.VERSION_11
}
ext {
ktLintOpts = [
"--reporter=plain",
"--reporter=checkstyle,output=${buildDir}/ktlint-report.xml"
]
moduleName = "XXX"
mainSourceDir = file("/src/main/kotlin")
classesDir = file("${buildDir}/classes")
docsDir = file("${buildDir}/doc")
ktlintHome = System.getenv("KTLINT_HOME")
if (!project.hasProperty("ktlintHome")) {
throw new GradleException("Variable KTLINT_HOME is undefined")
}
userHome = System.getProperty("user.home")
repoDir = file("${userHome}/.m2/repository")
libDir = file("${userHome}/AppData/Local/Temp/lib")
pluginsClasspath = files(
"${repoDir}/org/jetbrains/kotlinx/kotlinx-coroutines-core/${kotlinxVersion}/kotlinx-coroutines-core-${kotlinxVersion}.jar",
"${libDir}/kotlinx-html-jvm-${kotlinxHtmlVersion}.jar",
"${libDir}/kotlin-analysis-compiler-${kotlinVersion}.jar",
"${libDir}/kotlin-analysis-intellij-${kotlinVersion}.jar",
"${libDir}/dokka-analysis-${kotlinVersion}.jar",
"${libDir}/dokka-base-${kotlinVersion}.jar"
)
kotlinMain = "Main"
if (project.hasProperty("mainClassName") && mainClassName?.trim()) kotlinMain = mainClassName
javaMain = "Main"
if (project.hasProperty("javaMainClassName") && javaMainClassName?.trim()) javaMain = javaMainClassName
}
detekt {
config = files("../detekt-config.yml")
reports {
// see https://detekt.github.io/detekt/reporting.html
html {
enabled = false
}
sarif {
enabled = false
}
txt {
enabled = true
destination = file("${buildDir}/detekt-report.txt")
}
xml {
enabled = false
}
}
}
sourceSets {
// Default: srcDirs "src/main/kotlin"
main.kotlin.srcDirs mainSourceDir
}
clean.doLast {
buildDir.deleteDir()
}
task lint(type: JavaExec) {
description "Analyze Kotlin source files with KtLint"
mainClass = "-jar"
args "${ktlintHome}/ktlint.jar " + ktLintOpts + sourceSets.main.allSource.files
}
checkstyle {
maxErrors = 10
}
compileKotlin {
// dependsOn lint
description "Compile Kotlin source files"
kotlinOptions {
// Tool options
// suppressWarnings = true
verbose = false
// Common options
apiVersion = "1.6"
languageVersion = "1.6"
// JVM options
jvmTarget = "17" // "11", "1.8"
}
}
compileKotlin.doFirst {
if (!classesDir.exists()) classesDir.mkdirs()
}
build {
dependsOn compileKotlin
}
// see https://kotlin.github.io/dokka/1.4.0/user_guide/gradle/usage/
// available tasks: dokkaHtml, dokkaJavadoc, dokkaGfm and dokkaJekyll
tasks.dokkaHtml.configure {
outputDirectory.set(docsDir)
}
task run(type: JavaExec) {
dependsOn compileKotlin
description "Execute Kotlin main class $kotlinMain"
classpath sourceSets.main.runtimeClasspath
mainClass = kotlinMain
if (args == null) args ""
}
task runJava(type: JavaExec) {
doFirst {
println()
}
description "Execute Java main class $javaMain"
classpath sourceSets.main.runtimeClasspath
mainClass = javaMain
if (args == null) args ""
}
repositories {
mavenCentral()
maven { // e.g. dokka-gradle-plugin
url "https://dl.bintray.com/kotlin/dokka"
}
maven {
url "https://dl.bintray.com/kotlin/kotlin-dev"
}
}
dependencies {
implementation "io.gitlab.arturbosch.detekt:detekt-cli:$detektVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
// implementation "org.jetbrains.dokka:dokka-gradle-plugin:$dokkaVersion"
implementation "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion"
api "junit:junit:$junitVersion"
testImplementation "junit:junit:$junitVersion"
}