-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
261 lines (220 loc) · 8.3 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
plugins {
id("java")
id("java-library")
id("maven-publish")
id("signing")
id("com.github.ben-manes.versions") version "0.50.0" // For dependency updates
kotlin("jvm") version "1.9.0"
}
group = "com.github.SquareCodeFX"
version = "1.0.0"
description = "A Java/Kotlin client library for the ProxyCheck.io API v2"
repositories {
mavenCentral()
}
dependencies {
// Kotlin standard library
implementation(kotlin("stdlib"))
// HTTP client
implementation("com.squareup.okhttp3:okhttp:4.11.0")
// JSON parsing
implementation("com.google.code.gson:gson:2.10.1")
// Kotlin Coroutines
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
// Testing
testImplementation(platform("org.junit:junit-bom:5.10.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("org.mockito:mockito-core:5.4.0")
testImplementation("org.mockito.kotlin:mockito-kotlin:5.0.0")
}
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
tasks.test {
useJUnitPlatform()
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "11"
freeCompilerArgs = listOf("-Xjsr305=strict")
}
}
tasks.javadoc {
if (JavaVersion.current().isJava9Compatible) {
(options as StandardJavadocDocletOptions).addBooleanOption("html5", true)
}
options.encoding = "UTF-8"
}
tasks.jar {
manifest {
attributes(
mapOf(
"Implementation-Title" to project.name,
"Implementation-Version" to project.version,
"Implementation-Vendor" to "SquareCodeFX",
"Built-By" to System.getProperty("user.name"),
"Built-JDK" to System.getProperty("java.version"),
"Created-By" to "Gradle ${gradle.gradleVersion}",
"Automatic-Module-Name" to "io.proxycheck.api"
)
)
}
}
// Configure JitPack specific tasks
tasks.register("javadocJar", Jar::class) {
archiveClassifier.set("javadoc")
from(tasks.javadoc)
}
tasks.register("sourcesJar", Jar::class) {
archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
}
// Only sign artifacts if signing keys are available
signing {
setRequired(false) // Only sign when publishing to Maven Central
sign(publishing.publications)
}
// Add a specific task for JitPack
tasks.register("prepareForJitPack") {
dependsOn("build", "sourcesJar", "javadocJar", "publishToMavenLocal")
doLast {
println("JitPack build prepared successfully")
}
}
// Task to update version in README.md
tasks.register("updateReadmeVersion") {
doLast {
val readmeFile = file("README.md")
val readmeContent = readmeFile.readText()
// Update version in Gradle dependency
val updatedGradleContent = readmeContent.replace(
Regex("implementation\\(\"com.github.SquareCodeFX:ProxycheckIOApi:[^\"]+\"\\)"),
"implementation(\"com.github.SquareCodeFX:ProxycheckIOApi:${project.version}\")"
)
// Update version in Maven dependency
val updatedContent = updatedGradleContent.replace(
Regex("<version>[^<]+</version>\\s*</dependency>"),
"<version>${project.version}</version>\n</dependency>"
)
readmeFile.writeText(updatedContent)
println("Updated README.md with version ${project.version}")
}
}
// Make the build task depend on updateReadmeVersion
tasks.named("build") {
dependsOn("updateReadmeVersion")
}
// Task to generate a changelog from Git commits
tasks.register("generateChangelog") {
doLast {
val changelogFile = file("CHANGELOG.md")
val changelog = StringBuilder()
changelog.appendLine("# Changelog")
changelog.appendLine("")
changelog.appendLine("All notable changes to this project will be documented in this file.")
changelog.appendLine("")
changelog.appendLine("The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),")
changelog.appendLine("and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).")
changelog.appendLine("")
// Add the current version
// Use a simple approach for the date
val currentDate = try {
val process = ProcessBuilder("date", "+%Y-%m-%d")
.redirectErrorStream(true)
.start()
val result = process.inputStream.bufferedReader().use { it.readText().trim() }
process.waitFor()
result
} catch (e: Exception) {
"YYYY-MM-DD" // Fallback if the date command fails
}
changelog.appendLine("## [${project.version}] - ${currentDate}")
changelog.appendLine("")
// Try to get Git commits for the current version
try {
val process = ProcessBuilder("git", "log", "--pretty=format:- %s", "-n", "10")
.redirectErrorStream(true)
.start()
process.inputStream.bufferedReader().use { reader ->
reader.lines().forEach { line ->
if (!line.contains("Update version") && !line.contains("Generate changelog")) {
changelog.appendLine(line)
}
}
}
val exitCode = process.waitFor()
if (exitCode != 0) {
changelog.appendLine("- Initial release")
}
} catch (e: Exception) {
changelog.appendLine("- Initial release")
println("Could not get Git commits: ${e.message}")
}
// Only write the file if it doesn't exist or if we're not in the initial release
if (!changelogFile.exists() || project.version.toString() != "1.0.0") {
changelogFile.writeText(changelog.toString())
println("Generated CHANGELOG.md")
} else {
println("CHANGELOG.md already exists, skipping generation")
}
}
}
// Make the build task depend on generateChangelog
tasks.named("build") {
dependsOn("generateChangelog")
}
// Configure the dependency updates plugin
tasks.named<com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask>("dependencyUpdates") {
checkForGradleUpdate = true
outputFormatter = "json,xml,html"
outputDir = "build/reports/dependencyUpdates"
reportfileName = "dependency-updates"
// Reject versions with alpha, beta, rc, cr, m, preview, etc.
rejectVersionIf {
isNonStable(candidate.version) && !isNonStable(currentVersion)
}
}
// Helper function to check if a version is stable
fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) }
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
val isStable = stableKeyword || regex.matches(version)
return !isStable
}
publishing {
publications {
create<MavenPublication>("maven") {
groupId = project.group.toString()
artifactId = "ProxycheckIOApi"
version = project.version.toString()
from(components["java"])
// Include the custom javadoc and sources JARs
artifact(tasks["javadocJar"])
artifact(tasks["sourcesJar"])
pom {
name.set("ProxyCheck.io API Client")
description.set(project.description)
url.set("https://github.com/SquareCodeFX/ProxycheckIOApi")
licenses {
license {
name.set("MIT License")
url.set("https://opensource.org/licenses/MIT")
}
}
developers {
developer {
id.set("SquareCodeFX")
name.set("SquareCodeFX")
url.set("https://github.com/SquareCodeFX")
}
}
scm {
connection.set("scm:git:git://github.com/SquareCodeFX/ProxycheckIOApi.git")
developerConnection.set("scm:git:ssh://github.com:SquareCodeFX/ProxycheckIOApi.git")
url.set("https://github.com/SquareCodeFX/ProxycheckIOApi")
}
}
}
}
}