-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
268 lines (227 loc) · 9.31 KB
/
build.gradle.kts
File metadata and controls
268 lines (227 loc) · 9.31 KB
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
262
263
264
265
266
267
268
import java.time.Duration
import org.w3c.dom.Element
import javax.xml.parsers.DocumentBuilderFactory
plugins {
base
val kotlinVersion = "1.9.24"
kotlin("jvm") version kotlinVersion apply false
kotlin("plugin.serialization") version kotlinVersion apply false
id("java-library")
id("maven-publish")
publishing
signing
java
id("jacoco-report-aggregation")
id("com.github.kt3k.coveralls") version "2.12.2"
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
}
jacoco {
toolVersion = "0.8.12"
}
allprojects {
apply(plugin = "java")
group = "com.phodal.chapi"
version = "3.0.0-alpha"
description =
"Chapi is A common hierarchical abstract parser && information convertor, streamlines code analysis by converting diverse language source code into a unified abstract model, simplifying cross-language development."
repositories {
mavenCentral()
mavenLocal()
}
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8
}
subprojects {
apply(plugin = "java-library")
apply(plugin = "maven-publish")
apply(plugin = "signing")
apply(plugin = "publishing")
apply(plugin = "jacoco")
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
}
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
versionMapping {
usage("java-api") {
fromResolutionOf("runtimeClasspath")
}
usage("java-runtime") {
fromResolutionResult()
}
}
pom {
name.set("Chapi")
description.set("Chapi is A common language meta information convertor, convert different languages to same meta-data model")
url.set("https://github.com/phodal/chapi")
licenses {
license {
name.set("MPL 2.0")
url.set("https://github.com/phodal/chapi/blob/master/LICENSE")
}
}
developers {
developer {
id.set("Modernizing")
name.set("Modernizing Team")
email.set("h@phodal.com")
}
}
scm {
connection.set("scm:git:git://github.com/phodal/chapi.git")
developerConnection.set("scm:git:ssh://github.com/phodal/chapi.git")
url.set("https://github.com/phodal/chapi/")
}
}
}
}
repositories {
maven {
// Updated for new Sonatype Central Portal (OSSRH sunset on June 30, 2025)
val releasesRepoUrl = uri("https://ossrh-staging-api.central.sonatype.com/service/local/staging/deploy/maven2/")
val snapshotsRepoUrl = uri("https://central.sonatype.com/repository/maven-snapshots/")
url = if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl
credentials {
username = (if (project.findProperty("sonatypeUsername") != null) project.findProperty("sonatypeUsername") else System.getenv("MAVEN_USERNAME")).toString()
password = (if (project.findProperty("sonatypePassword") != null) project.findProperty("sonatypePassword") else System.getenv("MAVEN_PASSWORD")).toString()
}
}
}
}
signing {
// Use GPG agent for signing (more secure, no password in config files)
val signingKeyName = project.findProperty("signing.gnupg.keyName") as String? ?: System.getenv("GPG_KEY_NAME")
if (signingKeyName != null) {
// Use GPG agent
useGpgCmd()
isRequired = true
} else {
// Fallback to traditional signing if GPG agent is not configured
val signingKeyId = project.findProperty("signing.keyId") as String? ?: System.getenv("GPG_KEY_ID")
val signingPassword = project.findProperty("signing.password") as String? ?: System.getenv("GPG_PASSPHRASE")
val signingKey = project.findProperty("signing.secretKeyRingFile") as String? ?: System.getenv("GPG_SECRET_KEY_RING_FILE")
isRequired = signingKeyId != null && signingPassword != null && signingKey != null
}
sign(publishing.publications["mavenJava"])
}
java {
withJavadocJar()
withSourcesJar()
}
// Ensure sourcesJar and kotlinSourcesJar tasks depend on ANTLR grammar generation
tasks.named("sourcesJar") {
dependsOn(tasks.withType<AntlrTask>())
}
// Also ensure kotlinSourcesJar depends on ANTLR tasks (if it exists)
tasks.matching { it.name == "kotlinSourcesJar" }.configureEach {
dependsOn(tasks.withType<AntlrTask>())
}
tasks.test {
finalizedBy(tasks.jacocoTestReport) // report is always generated after tests run
}
tasks.jacocoTestReport {
dependsOn(tasks.test) // tests are required to run before generating the report
}
tasks.jacocoTestReport {
reports {
xml.required.set(false)
csv.required.set(false)
html.outputLocation.set(layout.buildDirectory.dir("jacocoHtml"))
}
}
tasks.withType<JacocoReport> {
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.map {
fileTree(it).apply {
exclude("chapi/ast/antlr")
}
}))
}
}
}
dependencies {
jacocoAggregation(project(":chapi-domain"))
jacocoAggregation(project(":chapi-ast-java"))
jacocoAggregation(project(":chapi-ast-typescript"))
jacocoAggregation(project(":chapi-ast-go"))
jacocoAggregation(project(":chapi-ast-python"))
jacocoAggregation(project(":chapi-ast-c"))
jacocoAggregation(project(":chapi-ast-csharp"))
jacocoAggregation(project(":chapi-ast-kotlin"))
jacocoAggregation(project(":chapi-ast-scala"))
jacocoAggregation(project(":chapi-ast-cpp"))
jacocoAggregation(project(":chapi-ast-protobuf"))
jacocoAggregation(project(":chapi-ast-swift"))
jacocoAggregation(project(":chapi-ast-dart"))
jacocoAggregation(project(":chapi-parser-toml"))
jacocoAggregation(project(":chapi-parser-cmake"))
}
reporting {
reports {
val jacocoRootReport by creating(JacocoCoverageReport::class) {
testType.set(TestSuiteType.UNIT_TEST)
}
}
}
tasks.check {
dependsOn(tasks.named<JacocoReport>("jacocoRootReport"))
}
// Helper function to read Maven settings.xml
fun getMavenCredentials(): Pair<String?, String?> {
val settingsFile = file("${System.getProperty("user.home")}/.m2/settings.xml")
if (!settingsFile.exists()) {
return Pair(null, null)
}
try {
val factory = DocumentBuilderFactory.newInstance()
val builder = factory.newDocumentBuilder()
val doc = builder.parse(settingsFile)
val servers = doc.getElementsByTagName("server")
val targetServerIds = setOf("ossrh", "central", "sonatype-nexus-staging")
for (i in 0 until servers.length) {
val server = servers.item(i) as Element
val serverId = server.getElementsByTagName("id").item(0)?.textContent
if (serverId == null || serverId !in targetServerIds) {
continue
}
val username = server.getElementsByTagName("username").item(0)?.textContent
val password = server.getElementsByTagName("password").item(0)?.textContent
if (username != null && password != null) {
return Pair(username, password)
}
}
} catch (e: Exception) {
logger.warn("Failed to read Maven settings.xml: ${e.message}")
}
return Pair(null, null)
}
val (mavenUsername, mavenPassword) = getMavenCredentials()
// Configure Nexus Publishing for new Sonatype Central Portal
// See: https://central.sonatype.org/publish/publish-portal-ossrh-staging-api/#configuration
nexusPublishing {
repositories {
sonatype {
// New Central Portal API endpoints (required for accounts created after Feb 2021)
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
// Credentials: try gradle.properties, then environment variables, then Maven settings.xml
username.set(
project.findProperty("sonatypeUsername")?.toString()
?: System.getenv("MAVEN_USERNAME")
?: mavenUsername
)
password.set(
project.findProperty("sonatypePassword")?.toString()
?: System.getenv("MAVEN_PASSWORD")
?: mavenPassword
)
}
}
// Increase timeout for publishing operations
connectTimeout.set(Duration.ofMinutes(3))
clientTimeout.set(Duration.ofMinutes(3))
}