/
MavenPublishPlugin.kt
71 lines (61 loc) · 2.99 KB
/
MavenPublishPlugin.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
package com.vanniktech.maven.publish
import com.vanniktech.maven.publish.legacy.configurePlatform
import com.vanniktech.maven.publish.legacy.setCoordinates
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.plugins.signing.SigningPlugin
open class MavenPublishPlugin : Plugin<Project> {
override fun apply(project: Project) {
project.plugins.apply(MavenPublishBasePlugin::class.java)
val baseExtension = project.baseExtension
// Apply signing immediately. It is also applied by `signAllPublications` but the afterEvaluate means
// that it's APIs are not available for consumers without also using afterEvaluate.
project.plugins.apply(SigningPlugin::class.java)
val extension = project.extensions.create("mavenPublish", MavenPublishPluginExtension::class.java, project)
project.setCoordinates()
project.configurePlatform()
project.afterEvaluate {
val sonatypeHost = extension.sonatypeHost
// ignore old extension if new extension was already called
if (sonatypeHost != null && baseExtension.mavenCentral == null) {
// only print warning when sonatypeHost was not set through a gradle property, we will continue supporting this
if (extension.sonatypeHostProperty() == null) {
when (sonatypeHost) {
SonatypeHost.DEFAULT -> project.logger.warn(
"The project is currently configured to be published to " +
"Maven Central. To maintain the current behavior, you need to explicitly add SONATYPE_HOST=DEFAULT to " +
"your gradle.properties or add the following to your build files:\n" +
"mavenPublishing {" +
" publishToMavenCentral()" +
"}"
)
SonatypeHost.S01 -> project.logger.warn(
"Configuring the sonatypeHost through the DSL is deprecated. " +
"Remove the old option and then add either SONATYPE_HOST=S01 to your gradle.properties or add the " +
"following to your build files:\n" +
"mavenPublishing {" +
" publishToMavenCentral(\"S01\")" +
"}"
)
}
}
baseExtension.publishToMavenCentral(sonatypeHost)
}
// ignore old extension if new extension was already called
if (extension.releaseSigningEnabled && baseExtension.signing == null) {
if (extension.releaseSigningProperty() == null) {
project.logger.warn(
"The project is currently configured to be automatically sign release builds before " +
"publishing. To maintain the current behavior you will need to explicitly add " +
"RELEASE_SIGNING_ENABLED=true to your gradle.properties or add the following to your build files:\n" +
"mavenPublishing {" +
" signAllPublications()" +
"}"
)
}
baseExtension.signAllPublications()
}
baseExtension.pomFromGradleProperties()
}
}
}