|
| 1 | +/* |
| 2 | + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +plugins { |
| 17 | + `java-library` |
| 18 | + `maven-publish` |
| 19 | + signing |
| 20 | + checkstyle |
| 21 | + jacoco |
| 22 | + id("com.github.spotbugs") version "1.6.10" |
| 23 | + id("io.codearte.nexus-staging") version "0.21.0" |
| 24 | +} |
| 25 | + |
| 26 | +allprojects { |
| 27 | + group = "software.amazon.smithy" |
| 28 | + version = "0.1.0" |
| 29 | +} |
| 30 | + |
| 31 | +// The root project doesn't produce a JAR. |
| 32 | +tasks["jar"].enabled = false |
| 33 | + |
| 34 | +// Load the Sonatype user/password for use in publishing tasks. |
| 35 | +val sonatypeUser: String? by project |
| 36 | +val sonatypePassword: String? by project |
| 37 | + |
| 38 | +/* |
| 39 | + * Sonatype Staging Finalization |
| 40 | + * ==================================================== |
| 41 | + * |
| 42 | + * When publishing to Maven Central, we need to close the staging |
| 43 | + * repository and release the artifacts after they have been |
| 44 | + * validated. This configuration is for the root project because |
| 45 | + * it operates at the "group" level. |
| 46 | + */ |
| 47 | +if (sonatypeUser != null && sonatypePassword != null) { |
| 48 | + apply(plugin = "io.codearte.nexus-staging") |
| 49 | + |
| 50 | + nexusStaging { |
| 51 | + packageGroup = "software.amazon" |
| 52 | + stagingProfileId = "e789115b6c941" |
| 53 | + |
| 54 | + username = sonatypeUser |
| 55 | + password = sonatypePassword |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +repositories { |
| 60 | + mavenLocal() |
| 61 | + mavenCentral() |
| 62 | +} |
| 63 | + |
| 64 | +subprojects { |
| 65 | + val subproject = this |
| 66 | + |
| 67 | + /* |
| 68 | + * Java |
| 69 | + * ==================================================== |
| 70 | + */ |
| 71 | + if (subproject.name != "smithy-python-codegen-test") { |
| 72 | + apply(plugin = "java-library") |
| 73 | + |
| 74 | + java { |
| 75 | + sourceCompatibility = JavaVersion.VERSION_1_8 |
| 76 | + targetCompatibility = JavaVersion.VERSION_1_8 |
| 77 | + } |
| 78 | + |
| 79 | + tasks.withType<JavaCompile> { |
| 80 | + options.encoding = "UTF-8" |
| 81 | + } |
| 82 | + |
| 83 | + // Use Junit5's test runner. |
| 84 | + tasks.withType<Test> { |
| 85 | + useJUnitPlatform() |
| 86 | + } |
| 87 | + |
| 88 | + // Apply junit 5 and hamcrest test dependencies to all java projects. |
| 89 | + dependencies { |
| 90 | + testCompile("org.junit.jupiter:junit-jupiter-api:5.4.0") |
| 91 | + testRuntime("org.junit.jupiter:junit-jupiter-engine:5.4.0") |
| 92 | + testCompile("org.junit.jupiter:junit-jupiter-params:5.4.0") |
| 93 | + testCompile("org.hamcrest:hamcrest:2.1") |
| 94 | + } |
| 95 | + |
| 96 | + // Reusable license copySpec |
| 97 | + val licenseSpec = copySpec { |
| 98 | + from("${project.rootDir}/LICENSE") |
| 99 | + from("${project.rootDir}/NOTICE") |
| 100 | + } |
| 101 | + |
| 102 | + // Set up tasks that build source and javadoc jars. |
| 103 | + tasks.register<Jar>("sourcesJar") { |
| 104 | + metaInf.with(licenseSpec) |
| 105 | + from(sourceSets.main.get().allJava) |
| 106 | + archiveClassifier.set("sources") |
| 107 | + } |
| 108 | + |
| 109 | + tasks.register<Jar>("javadocJar") { |
| 110 | + metaInf.with(licenseSpec) |
| 111 | + from(tasks.javadoc) |
| 112 | + archiveClassifier.set("javadoc") |
| 113 | + } |
| 114 | + |
| 115 | + // Configure jars to include license related info |
| 116 | + tasks.jar { |
| 117 | + metaInf.with(licenseSpec) |
| 118 | + inputs.property("moduleName", subproject.extra["moduleName"]) |
| 119 | + manifest { |
| 120 | + attributes["Automatic-Module-Name"] = subproject.extra["moduleName"] |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + // Always run javadoc after build. |
| 125 | + tasks["build"].finalizedBy(tasks["javadoc"]) |
| 126 | + |
| 127 | + /* |
| 128 | + * Maven |
| 129 | + * ==================================================== |
| 130 | + */ |
| 131 | + apply(plugin = "maven-publish") |
| 132 | + apply(plugin = "signing") |
| 133 | + |
| 134 | + repositories { |
| 135 | + mavenLocal() |
| 136 | + mavenCentral() |
| 137 | + } |
| 138 | + |
| 139 | + publishing { |
| 140 | + repositories { |
| 141 | + mavenCentral { |
| 142 | + url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") |
| 143 | + credentials { |
| 144 | + username = sonatypeUser |
| 145 | + password = sonatypePassword |
| 146 | + } |
| 147 | + } |
| 148 | + } |
| 149 | + |
| 150 | + publications { |
| 151 | + create<MavenPublication>("mavenJava") { |
| 152 | + from(components["java"]) |
| 153 | + |
| 154 | + // Ship the source and javadoc jars. |
| 155 | + artifact(tasks["sourcesJar"]) |
| 156 | + artifact(tasks["javadocJar"]) |
| 157 | + |
| 158 | + // Include extra information in the POMs. |
| 159 | + afterEvaluate { |
| 160 | + pom { |
| 161 | + name.set(subproject.extra["displayName"].toString()) |
| 162 | + description.set(subproject.description) |
| 163 | + url.set("https://github.com/awslabs/smithy") |
| 164 | + licenses { |
| 165 | + license { |
| 166 | + name.set("Apache License 2.0") |
| 167 | + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") |
| 168 | + distribution.set("repo") |
| 169 | + } |
| 170 | + } |
| 171 | + developers { |
| 172 | + developer { |
| 173 | + id.set("smithy") |
| 174 | + name.set("Smithy") |
| 175 | + organization.set("Amazon Web Services") |
| 176 | + organizationUrl.set("https://aws.amazon.com") |
| 177 | + roles.add("developer") |
| 178 | + } |
| 179 | + } |
| 180 | + scm { |
| 181 | + url.set("https://github.com/awslabs/smithy.git") |
| 182 | + } |
| 183 | + } |
| 184 | + } |
| 185 | + } |
| 186 | + } |
| 187 | + } |
| 188 | + |
| 189 | + // Don't sign the artifacts if we didn't get a key and password to use. |
| 190 | + val signingKey: String? by project |
| 191 | + val signingPassword: String? by project |
| 192 | + if (signingKey != null && signingPassword != null) { |
| 193 | + signing { |
| 194 | + useInMemoryPgpKeys(signingKey, signingPassword) |
| 195 | + sign(publishing.publications["mavenJava"]) |
| 196 | + } |
| 197 | + } |
| 198 | + |
| 199 | + /* |
| 200 | + * CheckStyle |
| 201 | + * ==================================================== |
| 202 | + */ |
| 203 | + apply(plugin = "checkstyle") |
| 204 | + |
| 205 | + tasks["checkstyleTest"].enabled = false |
| 206 | + |
| 207 | + /* |
| 208 | + * Code coverage |
| 209 | + * ==================================================== |
| 210 | + */ |
| 211 | + apply(plugin = "jacoco") |
| 212 | + |
| 213 | + // Always run the jacoco test report after testing. |
| 214 | + tasks["test"].finalizedBy(tasks["jacocoTestReport"]) |
| 215 | + |
| 216 | + // Configure jacoco to generate an HTML report. |
| 217 | + tasks.jacocoTestReport { |
| 218 | + reports { |
| 219 | + xml.isEnabled = false |
| 220 | + csv.isEnabled = false |
| 221 | + html.destination = file("$buildDir/reports/jacoco") |
| 222 | + } |
| 223 | + } |
| 224 | + |
| 225 | + /* |
| 226 | + * Spotbugs |
| 227 | + * ==================================================== |
| 228 | + */ |
| 229 | + apply(plugin = "com.github.spotbugs") |
| 230 | + |
| 231 | + // We don't need to lint tests. |
| 232 | + tasks["spotbugsTest"].enabled = false |
| 233 | + |
| 234 | + // Configure the bug filter for spotbugs. |
| 235 | + tasks.withType<com.github.spotbugs.SpotBugsTask> { |
| 236 | + effort = "max" |
| 237 | + excludeFilterConfig = project.resources.text.fromFile("${project.rootDir}/config/spotbugs/filter.xml") |
| 238 | + } |
| 239 | + } |
| 240 | +} |
0 commit comments