2021-05-25 06:58:34 +02:00
|
|
|
import org.gradle.api.Project
|
|
|
|
import org.gradle.api.plugins.JavaPluginExtension
|
|
|
|
import org.gradle.api.publish.PublishingExtension
|
|
|
|
import org.gradle.api.publish.maven.MavenPublication
|
2022-01-03 18:41:07 +01:00
|
|
|
import org.gradle.jvm.toolchain.JavaLanguageVersion
|
2021-05-25 06:58:34 +02:00
|
|
|
import org.gradle.kotlin.dsl.configure
|
|
|
|
import org.gradle.kotlin.dsl.get
|
|
|
|
import org.gradle.kotlin.dsl.named
|
|
|
|
import java.io.ByteArrayOutputStream
|
|
|
|
|
|
|
|
fun Project.publishShadowJar() {
|
|
|
|
configurePublication {
|
|
|
|
artifact(tasks["shadowJar"])
|
|
|
|
artifact(tasks["sourcesJar"])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun Project.publishJavaComponents() {
|
|
|
|
configurePublication {
|
|
|
|
from(components["java"])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun Project.configurePublication(configurer: MavenPublication.() -> Unit) {
|
|
|
|
extensions.configure<PublishingExtension> {
|
|
|
|
publications.named<MavenPublication>("mavenJava") {
|
|
|
|
apply(configurer)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun Project.latestCommitHash(): String {
|
2023-11-06 04:11:35 +01:00
|
|
|
return runGitCommand(listOf("rev-parse", "--short", "HEAD"))
|
2021-05-25 06:58:34 +02:00
|
|
|
}
|
|
|
|
|
2023-08-11 08:16:23 +02:00
|
|
|
fun Project.latestCommitMessage(): String {
|
2023-11-06 04:11:35 +01:00
|
|
|
return runGitCommand(listOf("log", "-1", "--pretty=%B"))
|
2023-08-10 13:29:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fun Project.branchName(): String {
|
2023-11-06 04:11:35 +01:00
|
|
|
return runGitCommand(listOf("rev-parse", "--abbrev-ref", "HEAD"))
|
|
|
|
}
|
|
|
|
|
|
|
|
fun Project.runGitCommand(args: List<String>): String {
|
2023-08-10 13:29:03 +02:00
|
|
|
val byteOut = ByteArrayOutputStream()
|
|
|
|
exec {
|
2023-11-06 04:11:35 +01:00
|
|
|
commandLine = listOf("git") + args
|
2023-08-10 13:29:03 +02:00
|
|
|
standardOutput = byteOut
|
|
|
|
}
|
|
|
|
return byteOut.toString(Charsets.UTF_8.name()).trim()
|
|
|
|
}
|
|
|
|
|
2021-05-25 06:58:34 +02:00
|
|
|
fun JavaPluginExtension.javaTarget(version: Int) {
|
2022-01-03 18:41:07 +01:00
|
|
|
toolchain.languageVersion.set(JavaLanguageVersion.of(version))
|
2021-05-25 06:58:34 +02:00
|
|
|
}
|