-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublish.gradle.kts
120 lines (104 loc) · 4.36 KB
/
publish.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
// Helper method to load properties from multiple files
fun loadPropertiesFromFiles() {
val secretPropsFile = project.rootProject.file("local.properties")
val credentialPropsFile = project.rootProject.file("credential.properties")
val properties = Properties()
// First load from local.properties
if (secretPropsFile.exists()) {
secretPropsFile.inputStream().use { stream ->
properties.load(stream)
}
}
// Then load from credential.properties (this can overwrite properties from local.properties)
if (credentialPropsFile.exists()) {
credentialPropsFile.inputStream().use { stream ->
properties.load(stream)
}
}
// Store properties in project.ext so they can be accessed globally
properties.forEach { name, value -> extra[name.toString()] = value }
}
// Helper method to fetch required properties
fun getRequiredProperty(propertyName: String): String {
if (!project.hasProperty(propertyName)) {
throw GradleException("Missing required property: $propertyName")
}
return project.property(propertyName) as String
}
// Root-level Nexus publishing setup
if (project == rootProject) {
loadPropertiesFromFiles()
nexusPublishing {
repositories {
sonatype {
stagingProfileId.set(getRequiredProperty("sonatypeStagingProfileId"))
username.set(getRequiredProperty("publish.username"))
password.set(getRequiredProperty("publish.password"))
}
}
}
} else {
// Apply Maven Publish and Signing plugins
apply(plugin = "maven-publish")
apply(plugin = "signing")
// Register the Android sources JAR task
tasks.register<Jar>("androidSourcesJar") {
if (project.plugins.hasPlugin("com.android.library")) {
from(android.sourceSets["main"].java.srcDirs)
} else {
from(sourceSets["main"].java.srcDirs)
}
}
// Use project-specific properties for group, artifactId, and version
group = getRequiredProperty("PUBLISH_GROUP_ID")
version = getRequiredProperty("PUBLISH_VERSION")
val artifactId = getRequiredProperty("PUBLISH_ARTIFACT_ID")
afterEvaluate {
publishing {
publications {
create<MavenPublication>("release") {
this.artifactId = artifactId
this.groupId = group
this.version = version
// Add components based on module type
if (project.plugins.hasPlugin("com.android.library")) {
from(components["release"])
} else {
artifact("$buildDir/libs/${project.name}-${version}.jar")
}
// Add sources JAR
artifact(tasks.named<Jar>("androidSourcesJar"))
// Configure POM metadata
pom {
name.set(artifactId)
description.set(getRequiredProperty("PUBLISH_DESCRIPTION"))
url.set(getRequiredProperty("PUBLISH_URL"))
licenses {
license {
name.set(getRequiredProperty("PUBLISH_LICENSE_NAME"))
// Uncomment if required
// url.set(getRequiredProperty("PUBLISH_LICENSE_URL"))
}
}
developers {
developer {
id.set(getRequiredProperty("PUBLISH_DEVELOPER_ID"))
name.set(getRequiredProperty("PUBLISH_DEVELOPER_NAME"))
email.set(getRequiredProperty("PUBLISH_DEVELOPER_EMAIL"))
}
}
scm {
connection.set(getRequiredProperty("PUBLISH_SCM_CONNECTION"))
developerConnection.set(getRequiredProperty("PUBLISH_SCM_DEVELOPER_CONNECTION"))
url.set(getRequiredProperty("PUBLISH_SCM_URL"))
}
}
}
}
}
// Automatically sign publications
signing {
sign(publishing.publications["release"])
}
}
}