-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
166 lines (154 loc) · 6.62 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
166 lines (154 loc) · 6.62 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
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.tasks.PublishToMavenRepository
import org.gradle.api.tasks.bundling.Zip
import org.gradle.plugins.signing.SigningExtension
buildscript {
extra["kotlinVersion"] = "2.2.21"
extra["agpVersion"] = "9.3.1"
extra["kspVersion"] = "2.3.8"
extra["kotlinPoetVersion"] = "2.3.0"
extra["minSdk"] = 23
extra["targetSdk"] = 36
extra["compileSdk"] = 36
extra["groupId"] = "io.github.donglua.layoutx2c"
extra["versionName"] = "1.4.0"
}
plugins {
id("com.android.application") version "${extra["agpVersion"]}" apply false
id("com.android.library") version "${extra["agpVersion"]}" apply false
id("org.jetbrains.kotlin.android") version "${extra["kotlinVersion"]}" apply false
id("org.jetbrains.kotlin.jvm") version "${extra["kotlinVersion"]}" apply false
id("com.google.devtools.ksp") version "${extra["kspVersion"]}" apply false
id("com.vanniktech.maven.publish") version "0.36.0" apply false
id("com.gradle.plugin-publish") version "2.1.1" apply false
}
val publishingGroup = providers.environmentVariable("GROUP")
.orElse(rootProject.extra["groupId"] as String)
val publishingVersion = providers.environmentVariable("VERSION")
.orElse(rootProject.extra["versionName"] as String)
val enableMavenCentralPublishing = providers.gradleProperty("layoutx2c.enablePublishing").isPresent
val useGpgSigning = providers.gradleProperty("layoutx2c.useGpgSigning")
.map(String::toBoolean)
.orElse(false)
val centralPortalBundleRepositoryName = "centralPortalBundle"
val centralPortalStagingDir = layout.buildDirectory.dir("central-portal/staging")
val validateCentralPortalBundleInputs = tasks.register("validateCentralPortalBundleInputs") {
group = "publishing"
description = "Validates signing properties required for a Central Portal upload bundle."
doLast {
val missing = listOf("signingInMemoryKey", "signingInMemoryKeyPassword")
.filterNot { providers.gradleProperty(it).isPresent }
if (missing.isNotEmpty()) {
throw GradleException(
"Missing required Gradle properties for Central Portal bundle: ${missing.joinToString()}"
)
}
}
}
val cleanCentralPortalBundle = tasks.register<Delete>("cleanCentralPortalBundle") {
group = "publishing"
description = "Deletes Central Portal bundle staging outputs."
delete(layout.buildDirectory.dir("central-portal"))
}
val publishCentralPortalBundleComponents = tasks.register("publishCentralPortalBundleComponents") {
group = "publishing"
description = "Publishes all LayoutX2C components to a local Central Portal staging repository."
}
tasks.register<Zip>("buildCentralPortalBundle") {
group = "publishing"
description = "Builds a Maven Repository Layout zip for Sonatype Central Portal Publish Component."
archiveFileName.set("layoutx2c-${publishingVersion.get()}-central-bundle.zip")
destinationDirectory.set(layout.buildDirectory.dir("central-portal"))
from(centralPortalStagingDir)
dependsOn(publishCentralPortalBundleComponents)
}
subprojects {
group = publishingGroup.get()
version = publishingVersion.get()
if (enableMavenCentralPublishing) {
pluginManager.apply("com.vanniktech.maven.publish")
plugins.withId("com.vanniktech.maven.publish") {
configure<com.vanniktech.maven.publish.MavenPublishBaseExtension> {
publishToMavenCentral()
if (providers.gradleProperty("signingInMemoryKey").isPresent || useGpgSigning.get()) {
signAllPublications()
}
coordinates(
groupId = publishingGroup.get(),
artifactId = project.name,
version = publishingVersion.get()
)
pom {
name.set("LayoutX2C ${project.name}")
description.set("Compile-time XML layout to Kotlin code generation for Android")
inceptionYear.set("2026")
url.set("https://github.com/donglua/LayoutX2C")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("donglua")
name.set("donglua")
}
}
scm {
connection.set("scm:git:git://github.com/donglua/LayoutX2C.git")
developerConnection.set("scm:git:ssh://github.com/donglua/LayoutX2C.git")
url.set("https://github.com/donglua/LayoutX2C")
}
}
}
}
plugins.withId("maven-publish") {
extensions.configure<PublishingExtension>("publishing") {
repositories {
maven {
name = centralPortalBundleRepositoryName
url = centralPortalStagingDir.get().asFile.toURI()
}
}
}
}
plugins.withId("signing") {
extensions.configure<SigningExtension>("signing") {
if (useGpgSigning.get()) {
useGpgCmd()
}
}
}
} else if (name == "gradle-plugin") {
pluginManager.withPlugin("java-gradle-plugin") {
pluginManager.apply("maven-publish")
}
} else {
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
pluginManager.apply("maven-publish")
extensions.configure<PublishingExtension>("publishing") {
publications {
register<MavenPublication>("maven") {
from(components["java"])
}
}
}
}
}
}
gradle.projectsEvaluated {
val bundlePublishTasks = subprojects.flatMap { subproject ->
subproject.tasks.withType(PublishToMavenRepository::class.java)
.matching { it.repository.name == centralPortalBundleRepositoryName }
.toList()
}
bundlePublishTasks.forEach {
it.dependsOn(validateCentralPortalBundleInputs, cleanCentralPortalBundle)
}
publishCentralPortalBundleComponents.configure {
dependsOn(bundlePublishTasks)
}
}