|
| 1 | +import com.vanniktech.maven.publish.MavenPublishBaseExtension |
1 | 2 | import org.gradle.api.Plugin |
2 | 3 | import org.gradle.api.Project |
3 | 4 | import org.gradle.api.plugins.ExtensionContainer |
4 | | -import org.gradle.api.plugins.JavaPluginExtension |
5 | 5 | import org.gradle.api.publish.PublishingExtension |
6 | 6 | import org.gradle.jvm.tasks.Jar |
7 | 7 | import org.gradle.language.jvm.tasks.ProcessResources |
8 | 8 | import org.gradle.plugin.devel.GradlePluginDevelopmentExtension |
9 | | -import org.gradle.plugins.signing.SigningExtension |
10 | 9 |
|
11 | 10 | class PublishingPlugin : Plugin<Project> { |
12 | 11 |
|
13 | 12 | override fun apply(target: Project) = with(target) { |
14 | | - pluginManager.apply("maven-publish") |
| 13 | + pluginManager.apply("com.vanniktech.maven.publish") |
15 | 14 | pluginManager.apply("com.gradle.plugin-publish") |
16 | | - if (findConfig("SIGNING_PASSWORD").isNotEmpty()) { |
17 | | - pluginManager.apply("signing") |
18 | | - } |
19 | | - |
20 | | - extensions.configure<JavaPluginExtension> { |
21 | | - withSourcesJar() |
22 | | - withJavadocJar() |
23 | | - } |
| 15 | + pluginManager.apply("org.jetbrains.dokka") |
24 | 16 |
|
25 | 17 | pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { |
26 | | - pluginManager.apply("org.jetbrains.dokka") |
| 18 | + tasks.named("processResources", ProcessResources::class.java) { processResources -> |
| 19 | + processResources.from(rootProject.file("LICENSE")) |
| 20 | + } |
27 | 21 |
|
28 | | - tasks.named("javadocJar", Jar::class.java) { javadocJar -> |
| 22 | + tasks.named { it == "javadocJar" }.withType(Jar::class.java).configureEach { javadocJar -> |
29 | 23 | javadocJar.from(tasks.named("dokkaGeneratePublicationHtml")) |
30 | 24 | } |
31 | | - tasks.named("processResources", ProcessResources::class.java) { processResources -> |
32 | | - processResources.from(rootProject.file("LICENSE.txt")) |
| 25 | + } |
| 26 | + |
| 27 | + extensions.configure<MavenPublishBaseExtension> { |
| 28 | + publishToMavenCentral() |
| 29 | + coordinates(group.toString(), name, version.toString()) |
| 30 | + |
| 31 | + signAllPublications() |
| 32 | + |
| 33 | + configureBasedOnAppliedPlugins() |
| 34 | + |
| 35 | + pom { pom -> |
| 36 | + pom.name.set("${project.group}:${project.name}") |
| 37 | + pom.description.set(project.description) |
| 38 | + pom.url.set("https://github.com/usefulness/ktlint-gradle-plugin") |
| 39 | + pom.licenses { licenses -> |
| 40 | + licenses.license { license -> |
| 41 | + license.name.set("Apache-2.0") |
| 42 | + license.url.set("https://github.com/usefulness/ktlint-gradle-plugin/blob/master/LICENSE") |
| 43 | + } |
| 44 | + } |
| 45 | + pom.developers { developers -> |
| 46 | + developers.developer { developer -> |
| 47 | + developer.id.set("mateuszkwiecinski") |
| 48 | + developer.name.set("Mateusz Kwiecinski") |
| 49 | + developer.email.set("36954793+mateuszkwiecinski@users.noreply.github.com") |
| 50 | + } |
| 51 | + developers.developer { developer -> |
| 52 | + developer.id.set("jeremymailen") |
| 53 | + developer.name.set("Jeremy Mailen") |
| 54 | + } |
| 55 | + } |
| 56 | + pom.scm { scm -> |
| 57 | + scm.connection.set("scm:git:github.com/usefulness/keeper.git") |
| 58 | + scm.developerConnection.set("scm:git:ssh://github.com/usefulness/keeper.git") |
| 59 | + scm.url.set("https://github.com/usefulness/keeper/tree/master") |
| 60 | + } |
33 | 61 | } |
34 | 62 | } |
35 | 63 |
|
36 | 64 | extensions.configure<PublishingExtension> { |
37 | 65 | with(repositories) { |
38 | 66 | maven { maven -> |
39 | 67 | maven.name = "github" |
40 | | - maven.setUrl("https://maven.pkg.github.com/usefulness/keeper") |
| 68 | + maven.setUrl("https://github.com/usefulness/keeper/") |
41 | 69 | with(maven.credentials) { |
42 | 70 | username = "usefulness" |
43 | 71 | password = findConfig("GITHUB_TOKEN") |
44 | 72 | } |
45 | 73 | } |
46 | 74 | } |
47 | 75 | } |
48 | | - pluginManager.withPlugin("signing") { |
49 | | - with(extensions.extraProperties) { |
50 | | - set("signing.keyId", findConfig("SIGNING_KEY_ID")) |
51 | | - set("signing.password", findConfig("SIGNING_PASSWORD")) |
52 | | - set("signing.secretKeyRingFile", findConfig("SIGNING_SECRET_KEY_RING_FILE")) |
53 | | - } |
54 | | - |
55 | | - extensions.configure<SigningExtension>("signing") { signing -> |
56 | | - if (findConfig("SIGNING_PASSWORD").isNotEmpty()) { |
57 | | - signing.sign(extensions.getByType(PublishingExtension::class.java).publications) |
| 76 | + pluginManager.withPlugin("com.gradle.plugin-publish") { |
| 77 | + extensions.configure<GradlePluginDevelopmentExtension> { |
| 78 | + website.set("https://github.com/usefulness/keeper/") |
| 79 | + vcsUrl.set("https://github.com/usefulness/keeper.git") |
| 80 | + plugins.configureEach { plugin -> |
| 81 | + plugin.tags.set(listOf("android", "kotlin", "keeper", "proguard", "release", "android-test")) |
| 82 | + plugin.description = "A Gradle plugin that infers Proguard/R8 keep rules for androidTest sources." |
| 83 | + plugin.displayName = "A Gradle plugin that infers Proguard/R8 keep rules for androidTest sources." |
58 | 84 | } |
59 | 85 | } |
60 | 86 | } |
61 | | - |
62 | | - extensions.configure<GradlePluginDevelopmentExtension> { |
63 | | - website.set("https://github.com/usefulness/keeper/") |
64 | | - vcsUrl.set("https://github.com/usefulness/keeper.git") |
65 | | - plugins.configureEach { plugin -> |
66 | | - plugin.tags.set(listOf("android", "kotlin", "keeper", "proguard", "release", "android-test")) |
67 | | - plugin.description = "A Gradle plugin that infers Proguard/R8 keep rules for androidTest sources." |
68 | | - } |
69 | | - } |
70 | 87 | } |
71 | 88 |
|
72 | | - private inline fun <reified T: Any> ExtensionContainer.configure(crossinline receiver: T.() -> Unit) { |
| 89 | + private inline fun <reified T : Any> ExtensionContainer.configure(crossinline receiver: T.() -> Unit) { |
73 | 90 | configure(T::class.java) { receiver(it) } |
74 | 91 | } |
75 | 92 | } |
|
0 commit comments