|
6 | 6 | import org.gradle.api.tasks.testing.logging.TestExceptionFormat |
7 | 7 | import org.gradle.api.tasks.testing.logging.TestLogEvent |
8 | 8 |
|
| 9 | +val ciSigningKey: String? = System.getenv("PGP_PRIVATE_SIGNING_KEY") |
| 10 | +val ciSigningPassword: String? = System.getenv("PGP_PRIVATE_SIGNING_KEY_PASSWORD") |
| 11 | +val shouldSignCIRelease: Boolean |
| 12 | + get() = !ciSigningKey.isNullOrEmpty() && !ciSigningPassword.isNullOrEmpty() |
| 13 | + |
| 14 | +val lastCommitHash: String = providers.exec { |
| 15 | + commandLine("git", "rev-parse", "--short", "HEAD") |
| 16 | +}.standardOutput.asText.map { it.trim() }.get() |
| 17 | + |
9 | 18 | plugins { |
10 | 19 | alias(libs.plugins.google.protobuf) |
11 | 20 | checkstyle |
12 | 21 | `maven-publish` |
| 22 | + signing |
13 | 23 | } |
14 | 24 |
|
15 | 25 | java { |
@@ -112,47 +122,79 @@ protobuf { |
112 | 122 | // Run "./gradlew publishReleasePublicationToLocalRepository" to generate release JARs locally |
113 | 123 | publishing { |
114 | 124 | publications { |
| 125 | + val mavenGroupId = "net.newpipe" |
| 126 | + val mavenArtifactId = "extractor" |
| 127 | + fun MavenPublication.setupPOM() = pom { |
| 128 | + name = "NewPipe Extractor" |
| 129 | + description = "A library for extracting data from streaming websites, used in NewPipe" |
| 130 | + url = "https://github.com/TeamNewPipe/NewPipeExtractor" |
| 131 | + |
| 132 | + licenses { |
| 133 | + license { |
| 134 | + name = "GNU GENERAL PUBLIC LICENSE, Version 3" |
| 135 | + url = "https://www.gnu.org/licenses/gpl-3.0.txt" |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + scm { |
| 140 | + url = "https://github.com/TeamNewPipe/NewPipeExtractor" |
| 141 | + connection = "scm:git:git@github.com:TeamNewPipe/NewPipeExtractor.git" |
| 142 | + developerConnection = "scm:git:git@github.com:TeamNewPipe/NewPipeExtractor.git" |
| 143 | + } |
| 144 | + |
| 145 | + developers { |
| 146 | + developer { |
| 147 | + id = "newpipe" |
| 148 | + name = "Team NewPipe" |
| 149 | + email = "team@newpipe.net" |
| 150 | + } |
| 151 | + } |
| 152 | + } |
| 153 | + |
115 | 154 | create<MavenPublication>("release") { |
116 | | - groupId = "net.newpipe" |
117 | | - artifactId = "extractor" |
| 155 | + groupId = mavenGroupId |
| 156 | + artifactId = mavenArtifactId |
118 | 157 | version = rootProject.version.toString() |
119 | 158 |
|
120 | 159 | afterEvaluate { |
121 | 160 | from(components["java"]) |
122 | 161 | } |
123 | 162 |
|
124 | | - pom { |
125 | | - name = "NewPipe Extractor" |
126 | | - description = "A library for extracting data from streaming websites, used in NewPipe" |
127 | | - url = "https://github.com/TeamNewPipe/NewPipeExtractor" |
128 | | - |
129 | | - licenses { |
130 | | - license { |
131 | | - name = "GNU GENERAL PUBLIC LICENSE, Version 3" |
132 | | - url = "https://www.gnu.org/licenses/gpl-3.0.txt" |
133 | | - } |
134 | | - } |
135 | | - |
136 | | - scm { |
137 | | - url = "https://github.com/TeamNewPipe/NewPipeExtractor" |
138 | | - connection = "scm:git:git@github.com:TeamNewPipe/NewPipeExtractor.git" |
139 | | - developerConnection = "scm:git:git@github.com:TeamNewPipe/NewPipeExtractor.git" |
140 | | - } |
| 163 | + setupPOM() |
| 164 | + } |
| 165 | + create<MavenPublication>("snapshot") { |
| 166 | + groupId = mavenGroupId |
| 167 | + artifactId = mavenArtifactId |
| 168 | + version = "$lastCommitHash-SNAPSHOT" |
141 | 169 |
|
142 | | - developers { |
143 | | - developer { |
144 | | - id = "newpipe" |
145 | | - name = "Team NewPipe" |
146 | | - email = "team@newpipe.net" |
147 | | - } |
148 | | - } |
| 170 | + afterEvaluate { |
| 171 | + from(components["java"]) |
149 | 172 | } |
| 173 | + |
| 174 | + setupPOM() |
150 | 175 | } |
151 | 176 | repositories { |
| 177 | + maven { |
| 178 | + name = "sonatype" |
| 179 | + url = uri("https://central.sonatype.com/repository/maven-snapshots/") |
| 180 | + credentials { |
| 181 | + username = System.getenv("SONATYPE_MAVEN_CENTRAL_USERNAME") |
| 182 | + password = System.getenv("SONATYPE_MAVEN_CENTRAL_PASSWORD") |
| 183 | + } |
| 184 | + } |
152 | 185 | maven { |
153 | 186 | name = "local" |
154 | 187 | url = uri(layout.buildDirectory.dir("maven")) |
155 | 188 | } |
156 | 189 | } |
157 | 190 | } |
158 | 191 | } |
| 192 | + |
| 193 | +signing { |
| 194 | + useInMemoryPgpKeys(ciSigningKey, ciSigningPassword) |
| 195 | + sign(publishing.publications["snapshot"]) |
| 196 | +} |
| 197 | + |
| 198 | +tasks.withType<Sign> { |
| 199 | + onlyIf("Signing credentials are present (only used for maven central)") { shouldSignCIRelease } |
| 200 | +} |
0 commit comments