|
| 1 | +import com.diffplug.spotless.changelog.gradle.ChangelogExtension |
| 2 | +import java.util.Base64 |
| 3 | + |
| 4 | +plugins { |
| 5 | + `java-library` |
| 6 | + `maven-publish` |
| 7 | + signing |
| 8 | +} |
| 9 | + |
| 10 | +fun decode64(varName: String): String { |
| 11 | + val envValue = System.getenv(varName) ?: return "" |
| 12 | + return String(Base64.getDecoder().decode(envValue), Charsets.UTF_8) |
| 13 | +} |
| 14 | + |
| 15 | +java { |
| 16 | + withJavadocJar() |
| 17 | + withSourcesJar() |
| 18 | +} |
| 19 | + |
| 20 | +tasks.named("sourcesJar") { |
| 21 | + dependsOn(tasks.jar) |
| 22 | +} |
| 23 | + |
| 24 | +tasks.withType<Javadoc>().configureEach { |
| 25 | + options { |
| 26 | + (this as? StandardJavadocDocletOptions)?.apply { |
| 27 | + encoding = Charsets.UTF_8.name() |
| 28 | + addStringOption("Xdoclint:none", "-quiet") |
| 29 | + addStringOption("Xwerror", "-quiet") |
| 30 | + addStringOption("source", "17") |
| 31 | + val artifactId = project.findProperty("artifactId")?.toString() ?: project.name |
| 32 | + val org = project.findProperty("org")?.toString() ?: "diffplug" |
| 33 | + val name = project.findProperty("name")?.toString() ?: "spotless" |
| 34 | + val version = project.version.toString() |
| 35 | + val group = project.group.toString() |
| 36 | + val javadocInfo = |
| 37 | + "<h2><a href=\"https://github.com/$org/$name\" style=\"text-transform: none;\">$group:$artifactId:$version</a> by <a href=\"https://www.diffplug.com\" style=\"text-transform: none;\">DiffPlug</a></h2>" |
| 38 | + header = javadocInfo |
| 39 | + |
| 40 | + val dotdotGradle = if (project.name.startsWith("eclipse-")) "../../gradle" else "../gradle" |
| 41 | + linksOffline("https://docs.gradle.org/6.1.1/javadoc/", "$dotdotGradle/javadoc/gradle") |
| 42 | + val versionLast = rootProject.the<ChangelogExtension>().versionLast |
| 43 | + linksOffline( |
| 44 | + "https://javadoc.io/static/com.diffplug.spotless/spotless-lib/$versionLast", |
| 45 | + "$dotdotGradle/javadoc/spotless-lib", |
| 46 | + ) |
| 47 | + linksOffline( |
| 48 | + "https://javadoc.io/static/com.diffplug.spotless/spotless-lib-extra/$versionLast", |
| 49 | + "$dotdotGradle/javadoc/spotless-lib-extra", |
| 50 | + ) |
| 51 | + } |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +tasks.check { |
| 56 | + dependsOn(tasks.javadoc) |
| 57 | +} |
| 58 | + |
| 59 | +afterEvaluate { |
| 60 | + val isExt = project.name.startsWith("eclipse-") |
| 61 | + val artifactId = project.findProperty("artifactId")?.toString() ?: project.name |
| 62 | + val isPluginMaven = artifactId == "spotless-maven-plugin" |
| 63 | + val isPluginGradle = pluginManager.hasPlugin("java-gradle-plugin") |
| 64 | + |
| 65 | + publishing { |
| 66 | + publications { |
| 67 | + val pluginMaven = |
| 68 | + findByName("pluginMaven") as? MavenPublication |
| 69 | + ?: create<MavenPublication>("pluginMaven") { |
| 70 | + if (!isPluginGradle) { |
| 71 | + from(components["java"]) |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + pluginMaven.apply { |
| 76 | + groupId = project.group.toString() |
| 77 | + this.artifactId = artifactId |
| 78 | + version = project.version.toString() |
| 79 | + |
| 80 | + pom { |
| 81 | + name = artifactId |
| 82 | + description = project.description |
| 83 | + url = "https://github.com/${project.findProperty("org")}/${rootProject.name}" |
| 84 | + scm { |
| 85 | + url = "https://github.com/${project.findProperty("org")}/${rootProject.name}" |
| 86 | + connection = |
| 87 | + "scm:git:https://github.com/${project.findProperty("org")}/${rootProject.name}.git" |
| 88 | + developerConnection = |
| 89 | + "scm:git:ssh:git@github.com/${project.findProperty("org")}/${rootProject.name}.git" |
| 90 | + } |
| 91 | + licenses { |
| 92 | + license { |
| 93 | + if (isExt) { |
| 94 | + name = "Eclipse Public License - v 1.0" |
| 95 | + url = "https://www.eclipse.org/legal/epl-v10.html" |
| 96 | + } else { |
| 97 | + name = "The Apache Software License, Version 2.0" |
| 98 | + url = "https://www.apache.org/licenses/LICENSE-2.0.txt" |
| 99 | + } |
| 100 | + distribution = "repo" |
| 101 | + } |
| 102 | + } |
| 103 | + developers { |
| 104 | + if (isExt) { |
| 105 | + @Suppress("UNCHECKED_CAST") |
| 106 | + val devs = project.findProperty("developers") as? Map<String, Map<String, String>> |
| 107 | + devs?.forEach { (extId, extValues) -> |
| 108 | + developer { |
| 109 | + id = extId |
| 110 | + name = extValues["name"] |
| 111 | + email = extValues["email"] |
| 112 | + } |
| 113 | + } |
| 114 | + } else { |
| 115 | + if (isPluginMaven) { |
| 116 | + developer { |
| 117 | + id = "lutovich" |
| 118 | + name = "Konstantin Lutovich" |
| 119 | + email = "konstantin.lutovich@neotechnology.com" |
| 120 | + } |
| 121 | + } |
| 122 | + developer { |
| 123 | + id = "nedtwigg" |
| 124 | + name = "Ned Twigg" |
| 125 | + email = "ned.twigg@diffplug.com" |
| 126 | + } |
| 127 | + } |
| 128 | + } |
| 129 | + if (isPluginMaven) { |
| 130 | + withXml { |
| 131 | + val rootNode = asNode() |
| 132 | + val prerequisites = rootNode.appendNode("prerequisites") |
| 133 | + prerequisites.appendNode("maven", "3.1.0") |
| 134 | + } |
| 135 | + } |
| 136 | + } |
| 137 | + } |
| 138 | + } |
| 139 | + if (System.getenv("JITPACK") == "true" || project.version.toString().endsWith("-SNAPSHOT")) { |
| 140 | + signing { |
| 141 | + isRequired = false |
| 142 | + } |
| 143 | + } else { |
| 144 | + signing { |
| 145 | + val gpgKey = decode64("ORG_GRADLE_PROJECT_gpg_key64") |
| 146 | + useInMemoryPgpKeys( |
| 147 | + "0x4272C851", |
| 148 | + gpgKey, |
| 149 | + System.getenv("ORG_GRADLE_PROJECT_gpg_passphrase"), |
| 150 | + ) |
| 151 | + sign(publishing.publications) |
| 152 | + } |
| 153 | + |
| 154 | + val changelogProject = if (tasks.names.contains("changelogBump")) project else rootProject |
| 155 | + val changelogTasks = changelogProject.tasks |
| 156 | + |
| 157 | + tasks.jar { |
| 158 | + dependsOn(changelogTasks.named("changelogCheck")) |
| 159 | + } |
| 160 | + |
| 161 | + val thisProj = project |
| 162 | + changelogTasks.named("changelogBump") { |
| 163 | + dependsOn( |
| 164 | + ":${thisProj.path.removePrefix(":")}:publishPluginMavenPublicationToSonatypeRepository" |
| 165 | + ) |
| 166 | + dependsOn(":closeAndReleaseSonatypeStagingRepository") |
| 167 | + if (thisProj.tasks.names.contains("publishPlugins")) { |
| 168 | + dependsOn(thisProj.tasks.named("publishPlugins")) |
| 169 | + } |
| 170 | + } |
| 171 | + } |
| 172 | + } |
| 173 | +} |
| 174 | + |
| 175 | +tasks.withType<AbstractArchiveTask>().configureEach { |
| 176 | + isPreserveFileTimestamps = false |
| 177 | + isReproducibleFileOrder = true |
| 178 | +} |
0 commit comments