This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 119
/
build.gradle
81 lines (73 loc) · 2.51 KB
/
build.gradle
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
plugins {
id 'maven-publish'
id 'signing'
}
archivesBaseName = 'gax-bom'
project.version = "2.18.8-SNAPSHOT" // {x-version-update:gax-bom:current}
def mavenJavaDir = "$buildDir/publications/mavenJava"
def mavenJavaBomOutputFile = file(mavenJavaDir + '/pom-default.xml')
def mavenJavaBomAscOutputFile = file(mavenJavaDir + '/pom-default.xml.asc')
// Copy our pom.xml to the location where a generated POM would go
task copyPom() {
doLast {
new File(mavenJavaDir).mkdirs()
copy {
from 'pom.xml'
into mavenJavaDir
rename 'pom.xml', 'pom-default.xml'
}
}
}
// We want to use our own pom.xml instead of the generated one, so we disable
// the pom.xml generation and have the publish tasks depend on `copyPom` instead.
tasks.whenTaskAdded { task ->
if (task.name == 'generatePomFileForMavenJavaPublication') {
task.enabled = false
} else if (task.name == 'publishMavenJavaPublicationToMavenLocal') {
task.dependsOn copyPom
} else if (task.name == 'publishMavenJavaPublicationToMavenRepository') {
task.dependsOn copyPom
} else if (task.name == 'publishMavenJavaPublicationToSonatypeRepository') {
task.dependsOn copyPom
}
}
// We can't use the `publishing` section from the main build.gradle because
// we don't want all the Java artifacts, and we want to use our own pom.xml
// instead of the generated one.
publishing {
publications {
mavenJava(MavenPublication) {
version = project.version
artifact mavenJavaBomOutputFile
}
}
repositories {
maven {
url 'https://google.oss.sonatype.org/service/local/staging/deploy/maven2/'
credentials {
username = findProperty('ossrhUsername')
password = findProperty('ossrhPassword')
}
}
}
}
signing {
required { gradle.taskGraph.hasTask ":${name}:publishToSonatype" }
if (project.hasProperty('signing.gnupg.executable')) {
useGpgCmd()
}
sign publishing.publications
}
// Unlike other regular subprojects, pom.asc (signature file) generated by
// signing is not automatically picked up. It may be because gax-bom uses a
// pre-written pom.xml instead of using an auto-generated one.
// https://discuss.gradle.org/t/how-to-publish-artifacts-signatures-asc-files-using-maven-publish-plugin/7422
task addPomAscFileToPublication {
onlyIf { mavenJavaBomAscOutputFile.exists() }
doLast {
publishing.publications.mavenJava(MavenPublication) {
artifact(mavenJavaBomAscOutputFile) { extension 'pom.asc' }
}
}
}
signMavenJavaPublication.finalizedBy addPomAscFileToPublication