This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
/
build.gradle
104 lines (92 loc) · 2.77 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
buildscript {
repositories {
mavenLocal()
maven {
url 'https://plugins.gradle.org/m2/'
}
mavenCentral()
jcenter()
}
}
archivesBaseName = "gax-bom"
project.version = "1.62.0" // {x-version-update:gax-bom:current}
ext {
mavenJavaDir = "$project.buildDir/publications/mavenJava"
mavenJavaBomOutputFile = file(mavenJavaDir + "/pom-default.xml")
}
// 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'
}
}
}
assemble.dependsOn copyPom
// 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
}
}
jar.enabled = false
// Remove the default jar archive which is added by the 'java' plugin.
// We could avoid this by not applying the 'java' plugin to all submodules of
// gax, but that would create a little bit of a mess, so we hack around it here.
configurations.archives.artifacts.with { archives ->
def artifacts = []
archives.each {
if (it.file =~ 'jar') {
// We can't just call `archives.remove(it)` here because it triggers
// a `ConcurrentModificationException`, so we add matching artifacts
// to another list, then remove those elements outside of this iteration.
artifacts.add(it)
}
}
artifacts.each {
archives.remove(it)
}
}
artifacts {
archives(mavenJavaBomOutputFile) {
builtBy copyPom
}
}
afterEvaluate {
// 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://oss.sonatype.org/service/local/staging/deploy/maven2/'
credentials {
username = project.hasProperty('ossrhUsername') ? project.getProperty('ossrhUsername') : null
password = project.hasProperty('ossrhPassword') ? project.getProperty('ossrhPassword') : null
}
}
}
}
signing {
if (!project.hasProperty('skip.signing')) {
if (project.hasProperty('signing.gnupg.executable')) {
useGpgCmd()
}
sign publishing.publications.mavenJava
}
}
}