-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathbuild.gradle.kts
218 lines (195 loc) · 7.34 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
import org.jetbrains.dokka.gradle.DokkaTask
// how to build? run ./gradlew
// where is the jar? build/lib/ipp-client-kotlin...jar
plugins {
id("org.jetbrains.kotlin.jvm") version "1.7.22"
id("org.jetbrains.dokka") version "1.7.20"
id("org.sonarqube") version "5.0.0.4638" // https://plugins.gradle.org/plugin/org.sonarqube
//id("org.sonarqube") version "3.5.0.2730" // supports java 8, dropped with 4.1
id("maven-publish")
id("java-library")
id("signing")
id("jacoco")
}
group = "de.gmuth"
version = "3.3-SNAPSHOT"
repositories {
mavenCentral()
}
// update gradle wrapper
// ./gradlew wrapper --gradle-version 7.6.4
// gradle 8? should be done when moved to kotlin.jvm plugin 1.9.x (to remove deprecation warnings)
dependencies {
testImplementation("org.jetbrains.kotlin:kotlin-test")
//testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}
// gradlew clean -x test build publishToMavenLocal
defaultTasks("assemble")
// https://docs.gradle.org/current/userguide/compatibility.html
val javaVersion = "11"
val kotlinVersion = "1.7"
tasks.apply {
// Kotlin
compileKotlin {
kotlinOptions {
jvmTarget = javaVersion
languageVersion = kotlinVersion
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = javaVersion
languageVersion = kotlinVersion
}
}
// Java
compileJava {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}
compileTestJava {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}
}
// ================= PUBLISHING ================
val repo = System.getProperty("repo")
publishing {
repositories {
if (repo == "github") {
// Github Packages:
// gradlew -Drepo=github publish
println("> maven repo github")
maven {
name = "GitHubPackages" // Must match regex [A-Za-z0-9_\-.]+.
url = uri("https://maven.pkg.github.com/gmuth/ipp-client-kotlin")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR")
password = project.findProperty("gpr.token") as String? ?: System.getenv("GITHUB_TOKEN")
}
}
}
// Maven Central:
// https://central.sonatype.org/publish/release/
// gradlew -Drepo=sonatype publish
// https://s01.oss.sonatype.org/#stagingRepositories (not Safari)
// "Close" and wait "for rule evalutaion"
// "Release"
if (repo == "sonatype") {
println("> maven repo sonatype")
maven {
name = "Sonatype"
//val snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
//val releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
//url = uri(if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl)
val host = "https://s01.oss.sonatype.org"
val path = if (version.toString().endsWith("SNAPSHOT")) "/content/repositories/snapshots/"
else "/service/local/staging/deploy/maven2/"
url = uri(host.plus(path))
println("> publish.url: $url")
credentials {
username = project.findProperty("ossrh.username") as String?
password = project.findProperty("ossrh.password") as String?
}
}
}
}
publications {
create<MavenPublication>("ippclient") {
from(components["java"])
pom {
name.set("ipp client library")
description.set("A client implementation of the ipp protocol, RFCs 8010, 8011, 3995 and 3996")
url.set("https://github.com/gmuth/ipp-client-kotlin")
licenses {
license {
name.set("MIT License")
url.set("https://raw.githubusercontent.com/gmuth/ipp-client-kotlin/master/LICENSE")
}
}
developers {
developer {
id.set("gmuth")
name.set("Gerhard Muth")
email.set("[email protected]")
}
}
scm {
connection.set("scm:git:git://github.com/gmuth/ipp-client-kotlin.git")
developerConnection.set("scm:git:ssh://[email protected]/gmuth/ipp-client-kotlin.git")
url.set("https://github.com/gmuth/ipp-client-kotlin")
}
}
}
}
}
java {
withSourcesJar()
}
repo?.run { // tasks for publishing on maven repo
// ====== signing ======
// set gradle.properties
// signing.keyId
// signing.password
// signing.secretKeyRingFile
// gradle signIppclientPublication
signing {
sign(publishing.publications["ippclient"])
}
// ====== produce sources.jar and javadoc.jar ======
java {
//withSourcesJar()
withJavadocJar()
}
// configure task javadocJar to take javadoc generated by dokkaJavadoc
tasks.named<Jar>("javadocJar") {
from(tasks.named<DokkaTask>("dokkaJavadoc"))
}
}
// ====== analyse code with SonarQube ======
val isRunningOnGithub = System.getenv("CI")?.toBoolean() ?: false
println("isRunningOnGithub=$isRunningOnGithub")
// https://docs.gradle.org/current/userguide/jacoco_plugin.html
jacoco {
// https://mvnrepository.com/artifact/org.jacoco/jacoco-maven-plugin
toolVersion = "0.8.11"
}
// required for sonarqube code coverage
// https://docs.sonarqube.org/latest/analysis/test-coverage/java-test-coverage
tasks.jacocoTestReport {
dependsOn(tasks.test)
// https://stackoverflow.com/questions/67725347/jacoco-fails-on-gradle-7-0-2-and-kotlin-1-5-10
reports {
xml.required.set(true)
csv.required.set(false)
html.required.set(false)
}
}
// gradle test jacocoTestReport sonar
// https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-gradle/
// configure token with 'publish analysis' permission in file ~/.gradle/gradle.properties:
// systemProp.sonar.login=<token>
//sonar {
// properties {
// property("sonar.host.url", "https://sonarcloud.io")
// property("sonar.projectKey", "gmuth_ipp-client-kotlin")
// property("sonar.organization", "gmuth")
// //property("sonar.verbose", "true")
// //property("sonar.junit.reportPaths", "build/test-results/test")
// //property("sonar.jacoco.reportPaths", "build/jacoco/test.exec")
// //property("sonar.coverage.jacoco.xmlReportPaths", "build/reports/jacoco/test/")
// }
//}
// https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner-for-gradle/
tasks.sonar {
dependsOn(tasks.jacocoTestReport) // for coverage
}
// ====== fat jar ======
//tasks.register("fatJar", Jar::class) {
// description = "Generates a fat jar for this project."
// group = JavaBasePlugin.DOCUMENTATION_GROUP
// manifest.attributes["Main-Class"] = "CopyNewJobsKt"
// duplicatesStrategy = DuplicatesStrategy.EXCLUDE
// from(configurations.runtimeClasspath.get().map(::zipTree))
// with(tasks.jar.get())
//}