-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
148 lines (130 loc) · 4.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
import cn.lalaki.pub.BaseCentralPortalPlusExtension
import java.io.ByteArrayOutputStream
import java.io.File
import java.util.Properties
plugins {
kotlin("jvm") version "2.0.20"
`java-library`
`maven-publish`
id("cn.lalaki.central") version "1.2.5"
signing
}
fun getLastVersion(defaultVersion: String = "1.0.0-SNAPSHOT"): String {
val stdout = ByteArrayOutputStream()
return try {
exec {
commandLine = "git describe --tags --abbrev=0".split(" ")
standardOutput = stdout
}
val tag = stdout.toString().trim()
if (tag.isEmpty()) {
defaultVersion
} else {
// Удалить первую букву 'v', если она есть
tag.removePrefix("v")
}
} catch (e: Exception) {
defaultVersion
}
}
group = "ru.moprules"
version = getLastVersion("0.0.1-SNAPSHOT")
repositories {
mavenCentral()
}
dependencies {
testImplementation(kotlin("test"))
implementation("com.google.code.gson:gson:[2.11.0, 3.0)")
implementation("com.squareup.retrofit2:retrofit:[2.11.0, 3.0)")
implementation("com.squareup.okhttp3:okhttp:[5.0.0-alpha.14, 6.0.0)")
implementation(kotlin("reflect"))
}
tasks.test {
useJUnitPlatform()
}
kotlin {
jvmToolchain(21)
}
// Загрузка свойств из файла
val localProperties = Properties().apply {
val localFile = File(rootProject.projectDir, "local.properties")
if (localFile.exists()) {
load(localFile.inputStream())
}
}
java {
withSourcesJar()
withJavadocJar()
}
val localMavenRepo = uri(layout.buildDirectory.dir("local_maven"))
centralPortalPlus {
url = localMavenRepo
username = localProperties["maven.username"] as String? ?: System.getenv("MAVEN_USER")
password = localProperties["maven.password"] as String? ?: System.getenv("MAVEN_PASS")
publishingType = BaseCentralPortalPlusExtension.PublishingType.AUTOMATIC // or PublishingType.AUTOMATIC
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
pom {
name = "ogson"
description = "Useful library for retorfit2"
url = "https://github.com/moprules/ogson"
licenses {
license {
name = "MIT"
url = "https://opensource.org/licenses/MIT"
}
}
developers {
developer {
id = "moprules"
name = "Mop Rules"
email = "rav-navini-gego-cutropal@yandex.ru"
}
}
scm {
connection = "scm:git:git://github.com/moprules/ogson.git.git"
developerConnection = "scm:git:ssh://github.com/moprules/ogson.git.git"
url = "https://github.com/moprules/ogson"
}
}
}
}
repositories {
// Публикация в GitHub Packages
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/moprules/ogson")
credentials {
// Имя пользователя GitHub (обычно GITHUB_ACTOR в Actions)
username = localProperties["gpr.user"] as String? ?: System.getenv("GITHUB_ACTOR")
// Токен доступа (обычно GITHUB_TOKEN в Actions)
password = localProperties["gpr.token"] as String? ?: System.getenv("GITHUB_TOKEN")
}
}
maven {
name = "localMavenRepo"
url = localMavenRepo
}
}
}
tasks.javadoc {
if (JavaVersion.current().isJava9Compatible) {
(options as StandardJavadocDocletOptions).addBooleanOption("html5", true)
}
}
signing {
val signingSecretKey: String? =
localProperties["signing.secretKey"] as String? ?: System.getenv("SIGNING_SECRET_KEY")
val signingPassword: String? = localProperties["signing.password"] as String? ?: System.getenv("SIGNING_PASSWORD")
useInMemoryPgpKeys(signingSecretKey, signingPassword)
sign(publishing.publications["mavenJava"])
}
tasks.register("lastVer") {
doLast {
val ver = getLastVersion()
println("project verson: $ver")
}
}