|
| 1 | +/* |
| 2 | + * Copyright 2023 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 | + id "java-library" |
| 18 | + id "maven-publish" |
| 19 | + id "signing" |
| 20 | + id "checkstyle" |
| 21 | + id "jacoco" |
| 22 | + id "com.github.spotbugs" version "5.0.14" |
| 23 | +} |
| 24 | + |
| 25 | +ext { |
| 26 | + // Load the plugin version from VERSION. |
| 27 | + libraryVersion = project.file("VERSION").getText('UTF-8').replace(System.lineSeparator(), "") |
| 28 | +} |
| 29 | + |
| 30 | +println "Smithy DocGen version: '${libraryVersion}'" |
| 31 | + |
| 32 | +allprojects { |
| 33 | + group = "software.amazon.smithy.docgen" |
| 34 | + version = libraryVersion |
| 35 | +} |
| 36 | + |
| 37 | +subprojects { |
| 38 | + apply plugin: "java-library" |
| 39 | + |
| 40 | + java { |
| 41 | + sourceCompatibility = JavaVersion.VERSION_17 |
| 42 | + targetCompatibility = JavaVersion.VERSION_17 |
| 43 | + } |
| 44 | + |
| 45 | + repositories { |
| 46 | + mavenLocal() |
| 47 | + mavenCentral() |
| 48 | + } |
| 49 | + |
| 50 | + dependencies { |
| 51 | + testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3") |
| 52 | + testImplementation("org.junit.jupiter:junit-jupiter-engine:5.9.3") |
| 53 | + testImplementation("org.junit.jupiter:junit-jupiter-params:5.9.3") |
| 54 | + testImplementation("org.hamcrest:hamcrest:2.2") |
| 55 | + } |
| 56 | + |
| 57 | + // Reusable license copySpec for building JARs |
| 58 | + def licenseSpec = copySpec { |
| 59 | + from "${project.rootDir}/LICENSE" |
| 60 | + from "${project.rootDir}/NOTICE" |
| 61 | + } |
| 62 | + |
| 63 | + // Set up tasks that build source and javadoc jars. |
| 64 | + task sourcesJar(type: Jar) { |
| 65 | + metaInf.with(licenseSpec) |
| 66 | + from { |
| 67 | + sourceSets.main.allJava |
| 68 | + } |
| 69 | + archiveClassifier = "sources" |
| 70 | + } |
| 71 | + |
| 72 | + // Build a javadoc JAR too. |
| 73 | + task javadocJar(type: Jar) { |
| 74 | + metaInf.with(licenseSpec) |
| 75 | + from { |
| 76 | + tasks.javadoc |
| 77 | + } |
| 78 | + archiveClassifier = "javadoc" |
| 79 | + } |
| 80 | + |
| 81 | + // Include an Automatic-Module-Name in all JARs. |
| 82 | + afterEvaluate { Project project -> |
| 83 | + tasks.jar { |
| 84 | + metaInf.with(licenseSpec) |
| 85 | + inputs.property("moduleName", project.ext["moduleName"]) |
| 86 | + manifest { |
| 87 | + attributes "Automatic-Module-Name": project.ext["moduleName"] |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + // Always run javadoc after build. |
| 93 | + tasks["build"].dependsOn(tasks["javadoc"]) |
| 94 | + |
| 95 | + // ==== Tests ==== |
| 96 | + // https://docs.gradle.org/current/samples/sample_java_multi_project_with_junit5_tests.html |
| 97 | + test { |
| 98 | + useJUnitPlatform() |
| 99 | + } |
| 100 | + // Log on passed, skipped, and failed test events if the `-Plog-tests` property is set. |
| 101 | + // https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/logging/TestLoggingContainer.html |
| 102 | + if (project.hasProperty("log-tests")) { |
| 103 | + test { |
| 104 | + testLogging { |
| 105 | + events = ["passed", "skipped", "failed"] |
| 106 | + exceptionFormat = "full" |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | + |
| 111 | + // ==== Maven ==== |
| 112 | + apply plugin: "maven-publish" |
| 113 | + apply plugin: "signing" |
| 114 | + |
| 115 | + publishing { |
| 116 | + publications { |
| 117 | + mavenJava(MavenPublication) { publication -> |
| 118 | + publication.from(components["java"]) |
| 119 | + |
| 120 | + // Ship the source and javadoc jars. |
| 121 | + artifact(tasks["sourcesJar"]) |
| 122 | + artifact(tasks["javadocJar"]) |
| 123 | + |
| 124 | + // Include extra information in the POMs. |
| 125 | + project.afterEvaluate { |
| 126 | + pom { |
| 127 | + name.set(project.ext["displayName"].toString()) |
| 128 | + description.set(project.description) |
| 129 | + url.set("https://github.com/smithy-lang/smithy-docgen") |
| 130 | + licenses { |
| 131 | + license { |
| 132 | + name.set("Apache License 2.0") |
| 133 | + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") |
| 134 | + distribution.set("repo") |
| 135 | + } |
| 136 | + } |
| 137 | + developers { |
| 138 | + developer { |
| 139 | + id.set("smithy") |
| 140 | + name.set("Smithy") |
| 141 | + organization.set("Amazon Web Services") |
| 142 | + organizationUrl.set("https://aws.amazon.com") |
| 143 | + roles.add("developer") |
| 144 | + } |
| 145 | + } |
| 146 | + scm { |
| 147 | + url.set("https://github.com/smithy-lang/smithy-docgen.git") |
| 148 | + } |
| 149 | + } |
| 150 | + } |
| 151 | + } |
| 152 | + } |
| 153 | + } |
| 154 | + |
| 155 | + task copyMavenMetadataForDevelopment(type: Copy) { |
| 156 | + from('build/tmp/publishMavenJavaPublicationToMavenLocal') { |
| 157 | + rename 'module-maven-metadata.xml', 'maven-metadata.xml' |
| 158 | + } |
| 159 | + |
| 160 | + def wdir = System.getProperty("user.home") + '/.m2/repository/software/amazon/smithy/docgen/' + project.name |
| 161 | + into(wdir) |
| 162 | + } |
| 163 | + |
| 164 | + publishToMavenLocal.finalizedBy(copyMavenMetadataForDevelopment) |
| 165 | + |
| 166 | + // ==== CheckStyle ==== |
| 167 | + // https://docs.gradle.org/current/userguide/checkstyle_plugin.html |
| 168 | + apply plugin: "checkstyle" |
| 169 | + tasks["checkstyleTest"].enabled = false |
| 170 | + |
| 171 | + // ==== Code coverage ==== |
| 172 | + // https://docs.gradle.org/current/userguide/jacoco_plugin.html |
| 173 | + apply plugin: "jacoco" |
| 174 | + // report is always generated after tests run |
| 175 | + test { |
| 176 | + finalizedBy jacocoTestReport |
| 177 | + } |
| 178 | + // tests are required to run before generating the report |
| 179 | + jacocoTestReport { |
| 180 | + dependsOn test |
| 181 | + } |
| 182 | + jacocoTestReport { |
| 183 | + reports { |
| 184 | + xml.enabled false |
| 185 | + csv.enabled false |
| 186 | + html.destination file("$buildDir/reports/jacoco") |
| 187 | + } |
| 188 | + } |
| 189 | + |
| 190 | + // ==== Spotbugs ==== |
| 191 | + // https://plugins.gradle.org/plugin/com.github.spotbugs |
| 192 | + apply plugin: "com.github.spotbugs" |
| 193 | + // We don't need to lint tests. |
| 194 | + tasks["spotbugsTest"].enabled = false |
| 195 | + // Configure the bug filter for spotbugs. |
| 196 | + spotbugs { |
| 197 | + effort = "max" |
| 198 | + excludeFilter = file("${project.rootDir}/config/spotbugs/filter.xml") |
| 199 | + } |
| 200 | +} |
| 201 | + |
| 202 | +// The root project doesn't produce a JAR. |
| 203 | +tasks["jar"].enabled = false |
0 commit comments