-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
239 lines (212 loc) · 7.91 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
import java.net.URL
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.DokkaBaseConfiguration
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
buildscript {
repositories { mavenCentral() }
dependencies { classpath("org.jetbrains.dokka:dokka-base:1.7.20") }
}
plugins {
kotlin("jvm") version "1.7.20"
kotlin("plugin.allopen") version "1.7.20"
id("com.diffplug.spotless") version "6.11.0"
id("org.jetbrains.dokka") version "1.7.20"
`maven-publish`
signing
jacoco // code coverage reports
}
extra.apply {
set("name", "KotlinParser")
set("description", "Used to parse Kotlin code")
set("group", "io.github.realyusufismail")
set("version", "0.0.1-SNAPSHOT")
set("dev_id", "yusuf")
set("dev_name", "Yusuf Ismail")
set("dev_email", "yusufgamer222@gmail.com")
set("dev_organization", "YDWK")
set("dev_organization_url", "https://github.com/YDWK")
set("gpl_name", "Apache-2.0 license")
set("gpl_url", "https://github.com/YDWK/KotlinParser/blob/master/LICENSE")
}
group = "io.github.realyusufismail" // used for publishing. DON'T CHANGE
val releaseVersion by extra(!version.toString().endsWith("-SNAPSHOT"))
apply(from = "gradle/tasks/incrementVersion.gradle.kts")
repositories { mavenCentral() }
dependencies {
// logger
api("ch.qos.logback:logback-classic:1.4.4")
api("ch.qos.logback:logback-core:1.4.4")
api("uk.org.lidalia:sysout-over-slf4j:1.0.2")
// tests
testImplementation(kotlin("test"))
testImplementation("org.jetbrains.kotlin:kotlin-test:1.7.20")
}
tasks.test {
useJUnitPlatform()
finalizedBy(tasks.jacocoTestReport) // report is always generated after tests run
}
tasks.jacocoTestReport {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
reports {
xml.required.set(true)
html.required.set(true)
}
finalizedBy("jacocoTestCoverageVerification")
}
configurations { all { exclude(group = "org.slf4j", module = "slf4j-log4j12") } }
tasks.withType<KotlinCompile> { kotlinOptions.jvmTarget = "17" }
spotless {
kotlin {
// Excludes build folder since it contains generated java classes.
targetExclude("build/**")
ktfmt("0.39").dropboxStyle()
licenseHeader(
"""/*
* Copyright 2022 YDWK inc.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
*
* you may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/ """)
}
kotlinGradle {
target("**/*.gradle.kts")
ktfmt("0.39").dropboxStyle()
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
}
java {
withJavadocJar()
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
tasks.javadoc {
if (JavaVersion.current().isJava9Compatible) {
(options as StandardJavadocDocletOptions).addBooleanOption("html5", true)
}
}
publishing {
val isReleaseVersion = !version.toString().endsWith("SNAPSHOT")
publications {
create<MavenPublication>("kotlinParser") {
from(components["java"])
// artifactId = project.artifactId // or maybe archiveBaseName?
pom {
name.set(extra["name"] as String)
description.set(extra["description"] as String)
url.set("https://www.ydwk.org/KotlinParser")
issueManagement {
system.set("GitHub")
url.set("https://github.com/YDWK/KotlinParser/issues")
}
licenses {
license {
name.set(extra["gpl_name"] as String)
url.set(extra["gpl_url"] as String)
}
}
ciManagement { system.set("GitHub Actions") }
inceptionYear.set("2022")
developers {
developer {
id.set(extra["dev_id"] as String)
name.set(extra["dev_name"] as String)
email.set(extra["dev_email"] as String)
organization.set(extra["dev_organization"] as String)
organizationUrl.set(extra["dev_organization_url"] as String)
}
}
scm {
connection.set("https://github.com/YDWK/KotlinParser.git")
developerConnection.set("scm:git:ssh://git@github.com/YDWK/KotlinParser.git")
url.set("github.com/YDWK/KotlinParser")
}
}
}
}
repositories {
maven {
name = "MavenCentral"
val releaseRepo = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
val snapshotRepo = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
url = uri((if (isReleaseVersion) releaseRepo else snapshotRepo))
credentials {
// try to get it from system gradle.properties
println("Trying to get credentials from system properties")
username =
when {
systemHasEnvVar("MAVEN_USERNAME") -> {
System.getenv("MAVEN_USERNAME")
}
project.hasProperty("MAVEN_USERNAME") -> {
project.property("MAVEN_USERNAME") as String
}
else -> {
logger.warn(
"MAVEN_USERNAME not found in system properties, meaning if you are trying to publish to maven central, it will fail")
null
}
}
password =
when {
systemHasEnvVar("MAVEN_PASSWORD") -> {
System.getenv("MAVEN_PASSWORD")
}
project.hasProperty("MAVEN_PASSWORD") -> {
project.property("MAVEN_PASSWORD") as String
}
else -> {
logger.warn(
"MAVEN_PASSWORD not found in system properties, meaning if you are trying to publish to maven central, it will fail")
null
}
}
}
}
}
}
fun systemHasEnvVar(varName: String): Boolean {
return System.getenv(varName) != null
}
signing {
afterEvaluate {
// println "sign: " + isReleaseVersion
val isRequired =
releaseVersion &&
(tasks.withType<PublishToMavenRepository>().find { gradle.taskGraph.hasTask(it) } !=
null)
setRequired(isRequired)
sign(publishing.publications["kotlinParser"])
}
}
tasks.getByName("dokkaHtml", DokkaTask::class) {
dokkaSourceSets.configureEach {
includes.from("Package.md")
jdkVersion.set(17)
sourceLink {
localDirectory.set(file("src/main/kotlin"))
remoteUrl.set(
URL("https://github.com/RealYusufIsmail/YDWK/tree/master/src/main/kotlin"))
remoteLineSuffix.set("#L")
}
pluginConfiguration<DokkaBase, DokkaBaseConfiguration> {
footerMessage = "Copyright © 2022 Yusuf Arfan Ismail and other YDWK contributors."
}
}
}