forked from apache/polaris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPublishingHelperPlugin.kt
170 lines (154 loc) · 6.9 KB
/
PublishingHelperPlugin.kt
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
167
168
169
170
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package publishing
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
import javax.inject.Inject
import org.gradle.api.*
import org.gradle.api.component.SoftwareComponentFactory
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin
import org.gradle.api.publish.tasks.GenerateModuleMetadata
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.javadoc.Javadoc
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.*
import org.gradle.plugins.signing.SigningExtension
import org.gradle.plugins.signing.SigningPlugin
/**
* Release-publishing helper plugin to generate publications that pass Sonatype validations,
* generate Apache release source tarball.
*
* The `release` Gradle project property triggers: signed artifacts + jars with Git information. The
* current Git HEAD must point to a Git tag.
*
* The `jarWithGitInfo` Gradle project property triggers: jars with Git information (not necessary
* with `release`).
*
* The task `sourceTarball` (available on the root project) generates a source tarball using `git
* archive`.
*
* The task `releaseEmailTemplate` generates the release-vote email subject + body. Outputs on the
* console and in the `build/distributions/` directory.
*
* Signing tip: If you want to use `gpg-agent`, set the `useGpgAgent` Gradle project property
*
* The following command publishes the project artifacts to your local maven repository, generates
* the source tarball - and uses `gpg-agent` to sign all artifacts and the tarball. Note that this
* requires a Git tag!
*
* ```
* ./gradlew publishToMavenLocal sourceTarball -Prelease -PuseGpgAgent
* ```
*
* You can generate signed artifacts when using the `signArtifacts` project property:
* ```
* ./gradlew publishToMavenLocal sourceTarball -PsignArtifacts -PuseGpgAgent
* ```
*/
@Suppress("unused")
class PublishingHelperPlugin
@Inject
constructor(private val softwareComponentFactory: SoftwareComponentFactory) : Plugin<Project> {
override fun apply(project: Project): Unit =
project.run {
extensions.create("publishingHelper", PublishingHelperExtension::class.java)
val isRelease = project.hasProperty("release")
val isSigning = isRelease || project.hasProperty("signArtifacts")
// Adds Git/Build/System related information to the generated jars, if the `release` project
// property is present. Do not add that information in development builds, so that the
// generated jars are still cacheable for Gradle.
if (isRelease || project.hasProperty("jarWithGitInfo")) {
// Runs `git`, considered expensive, so guarded behind project properties.
tasks.withType<Jar>().configureEach {
manifest { MemoizedGitInfo.gitInfo(rootProject, attributes) }
}
addAdditionalJarContent(this)
}
apply(plugin = "maven-publish")
apply(plugin = "signing")
// Generate a source tarball for a release to be uploaded to
// https://dist.apache.org/repos/dist/dev/<name>/apache-<name>-<version-with-rc>/
if (project == rootProject) {
configureOnRootProject(project)
}
if (isSigning) {
plugins.withType<SigningPlugin>().configureEach {
configure<SigningExtension> {
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
val publishing = project.extensions.getByType(PublishingExtension::class.java)
afterEvaluate { sign(publishing.publications.getByName("maven")) }
if (project.hasProperty("useGpgAgent")) {
useGpgCmd()
}
}
}
}
// Gradle complains when a Gradle module metadata ("pom on steroids") is generated with an
// enforcedPlatform() dependency - but Quarkus requires enforcedPlatform(), so we have to
// allow it.
tasks.withType<GenerateModuleMetadata>().configureEach {
suppressedValidationErrors.add("enforced-platform")
}
plugins.withType<MavenPublishPlugin>().configureEach {
configure<PublishingExtension> {
publications {
register<MavenPublication>("maven") {
val mavenPublication = this
afterEvaluate {
// This MUST happen in an 'afterEvaluate' to ensure that the Shadow*Plugin has
// been applied.
if (project.plugins.hasPlugin(ShadowPlugin::class.java)) {
configureShadowPublishing(project, mavenPublication, softwareComponentFactory)
} else {
from(components.firstOrNull { c -> c.name == "javaPlatform" || c.name == "java" })
}
suppressPomMetadataWarningsFor("testFixturesApiElements")
suppressPomMetadataWarningsFor("testFixturesRuntimeElements")
}
if (
plugins.hasPlugin("java-test-fixtures") &&
project.layout.projectDirectory.dir("src/testFixtures").asFile.exists()
) {
val testFixturesSourcesJar by
tasks.registering(org.gradle.api.tasks.bundling.Jar::class) {
val sourceSets: SourceSetContainer by project
from(sourceSets.named("testFixtures").get().allSource)
archiveClassifier.set("test-fixtures-sources")
}
tasks.named<Javadoc>("testFixturesJavadoc") { isFailOnError = false }
val testFixturesJavadocJar by
tasks.registering(org.gradle.api.tasks.bundling.Jar::class) {
from(tasks.named("testFixturesJavadoc"))
archiveClassifier.set("test-fixtures-javadoc")
}
artifact(testFixturesSourcesJar)
artifact(testFixturesJavadocJar)
}
tasks.named("generatePomFileForMavenPublication").configure {
configurePom(project, mavenPublication, this)
}
}
}
}
}
}
}