324 lines
11 KiB
Groovy
324 lines
11 KiB
Groovy
/*
|
|
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License").
|
|
* You may not use this file except in compliance with the License.
|
|
* A copy of the License is located at
|
|
*
|
|
* http://aws.amazon.com/apache2.0
|
|
*
|
|
* or in the "license" file accompanying this file. This file is distributed
|
|
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
|
* express or implied. See the License for the specific language governing
|
|
* permissions and limitations under the License.
|
|
*/
|
|
|
|
import java.util.stream.Collectors
|
|
import com.github.spotbugs.snom.Effort
|
|
|
|
plugins {
|
|
id "java-library"
|
|
id "maven-publish"
|
|
id "signing"
|
|
id "checkstyle"
|
|
id "jacoco"
|
|
id "com.github.spotbugs" version "6.0.8"
|
|
id "io.codearte.nexus-staging" version "0.30.0"
|
|
id "me.champeau.jmh" version "0.7.2"
|
|
id "com.github.johnrengelman.shadow" version "7.1.2"
|
|
id "org.jreleaser" version "1.12.0" apply false
|
|
}
|
|
|
|
ext {
|
|
// Load the Smithy version from VERSION.
|
|
libraryVersion = project.file("VERSION").getText('UTF-8').replace(System.lineSeparator(), "")
|
|
}
|
|
|
|
println "Smithy version: '${libraryVersion}'"
|
|
|
|
allprojects {
|
|
group = "software.amazon.smithy"
|
|
version = libraryVersion
|
|
}
|
|
|
|
// JReleaser publishes artifacts from a local staging repository, rather than maven local.
|
|
// https://jreleaser.org/guide/latest/examples/maven/staging-artifacts.html#_gradle
|
|
def stagingDirectory = rootProject.layout.buildDirectory.dir("staging")
|
|
|
|
subprojects {
|
|
apply plugin: "java-library"
|
|
|
|
java {
|
|
sourceCompatibility = JavaVersion.VERSION_1_8
|
|
targetCompatibility = JavaVersion.VERSION_1_8
|
|
}
|
|
|
|
repositories {
|
|
mavenLocal()
|
|
mavenCentral()
|
|
}
|
|
|
|
dependencies {
|
|
testImplementation "org.junit.jupiter:junit-jupiter-api:5.10.0"
|
|
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.10.0"
|
|
testImplementation "org.junit.jupiter:junit-jupiter-params:5.10.0"
|
|
testImplementation "org.hamcrest:hamcrest:2.1"
|
|
testCompileOnly "org.apiguardian:apiguardian-api:1.1.2"
|
|
}
|
|
|
|
// Reusable license copySpec for building JARs
|
|
def licenseSpec = copySpec {
|
|
from "${project.rootDir}/LICENSE"
|
|
from "${project.rootDir}/NOTICE"
|
|
}
|
|
|
|
// Set up tasks that build source and javadoc jars.
|
|
task sourcesJar(type: Jar) {
|
|
metaInf.with(licenseSpec)
|
|
from {
|
|
sourceSets.main.allSource
|
|
}
|
|
archiveClassifier = "sources"
|
|
}
|
|
|
|
// Build a javadoc JAR too.
|
|
task javadocJar(type: Jar) {
|
|
metaInf.with(licenseSpec)
|
|
from {
|
|
tasks.javadoc
|
|
}
|
|
archiveClassifier = "javadoc"
|
|
}
|
|
|
|
// Include an Automatic-Module-Name in all JARs.
|
|
afterEvaluate { Project project ->
|
|
tasks.jar {
|
|
metaInf.with(licenseSpec)
|
|
inputs.property("moduleName", project.ext["moduleName"])
|
|
manifest {
|
|
attributes "Automatic-Module-Name": project.ext["moduleName"]
|
|
}
|
|
}
|
|
}
|
|
|
|
// Always run javadoc after build.
|
|
tasks["build"].dependsOn(tasks["javadoc"])
|
|
|
|
// ==== Tests ====
|
|
// https://docs.gradle.org/current/samples/sample_java_multi_project_with_junit5_tests.html
|
|
test {
|
|
useJUnitPlatform()
|
|
}
|
|
// Log on passed, skipped, and failed test events if the `-Plog-tests` property is set.
|
|
// https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/logging/TestLoggingContainer.html
|
|
if (project.hasProperty("log-tests")) {
|
|
test {
|
|
testLogging {
|
|
events = ["passed", "skipped", "failed"]
|
|
exceptionFormat = "full"
|
|
}
|
|
}
|
|
}
|
|
|
|
// ==== Maven ====
|
|
apply plugin: "maven-publish"
|
|
apply plugin: "signing"
|
|
apply plugin: "com.github.johnrengelman.shadow"
|
|
|
|
// This is a little hacky, but currently needed to build a shadowed CLI JAR and smithy-syntax JAR with the same
|
|
// customizations as other JARs.
|
|
if (project.name != "smithy-cli" && project.name != "smithy-syntax") {
|
|
tasks.shadowJar.enabled = false
|
|
}
|
|
|
|
publishing {
|
|
repositories {
|
|
// JReleaser's `publish` task publishes to all repositories, so only configure one.
|
|
maven {
|
|
name = "localStaging"
|
|
url = stagingDirectory
|
|
}
|
|
}
|
|
|
|
publications {
|
|
mavenJava(MavenPublication) { publication ->
|
|
if (tasks.shadowJar.enabled) {
|
|
project.shadow.component(publication)
|
|
} else {
|
|
publication.from(components["java"])
|
|
}
|
|
|
|
// Ship the source and javadoc jars.
|
|
artifact(tasks["sourcesJar"])
|
|
artifact(tasks["javadocJar"])
|
|
|
|
// Include extra information in the POMs.
|
|
project.afterEvaluate {
|
|
pom {
|
|
name.set(project.ext["displayName"].toString())
|
|
description.set(project.description)
|
|
url.set("https://github.com/smithy-lang/smithy")
|
|
licenses {
|
|
license {
|
|
name.set("Apache License 2.0")
|
|
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
|
|
distribution.set("repo")
|
|
}
|
|
}
|
|
developers {
|
|
developer {
|
|
id.set("smithy")
|
|
name.set("Smithy")
|
|
organization.set("Amazon Web Services")
|
|
organizationUrl.set("https://aws.amazon.com")
|
|
roles.add("developer")
|
|
}
|
|
}
|
|
scm {
|
|
url.set("https://github.com/smithy-lang/smithy.git")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Don't sign the artifacts if we didn't get a key and password to use.
|
|
if (project.hasProperty("signingKey") && project.hasProperty("signingPassword")) {
|
|
signing {
|
|
useInMemoryPgpKeys(
|
|
(String) project.property("signingKey"),
|
|
(String) project.property("signingPassword"))
|
|
sign(publishing.publications["mavenJava"])
|
|
}
|
|
}
|
|
}
|
|
|
|
task copyMavenMetadataForDevelopment(type: Copy) {
|
|
from('build/tmp/publishMavenJavaPublicationToMavenLocal') {
|
|
rename 'module-maven-metadata.xml', 'maven-metadata.xml'
|
|
}
|
|
|
|
def wdir = System.getProperty("user.home") + '/.m2/repository/software/amazon/smithy/' + project.name
|
|
into(wdir)
|
|
}
|
|
|
|
publishToMavenLocal.finalizedBy(copyMavenMetadataForDevelopment)
|
|
|
|
// ==== CheckStyle ====
|
|
// https://docs.gradle.org/current/userguide/checkstyle_plugin.html
|
|
apply plugin: "checkstyle"
|
|
tasks["checkstyleTest"].enabled = false
|
|
|
|
// ==== Code coverage ====
|
|
// https://docs.gradle.org/current/userguide/jacoco_plugin.html
|
|
apply plugin: "jacoco"
|
|
// report is always generated after tests run
|
|
test {
|
|
finalizedBy jacocoTestReport
|
|
}
|
|
// tests are required to run before generating the report
|
|
jacocoTestReport {
|
|
dependsOn test
|
|
}
|
|
jacocoTestReport {
|
|
reports {
|
|
xml.required.set(false)
|
|
csv.required.set(false)
|
|
html.destination file("$buildDir/reports/jacoco")
|
|
}
|
|
}
|
|
|
|
// ==== Spotbugs ====
|
|
// https://plugins.gradle.org/plugin/com.github.spotbugs
|
|
apply plugin: "com.github.spotbugs"
|
|
// We don't need to lint tests.
|
|
tasks["spotbugsTest"].enabled = false
|
|
// Configure the bug filter for spotbugs.
|
|
spotbugs {
|
|
effort = Effort.MAX
|
|
excludeFilter = file("${project.rootDir}/config/spotbugs/filter.xml")
|
|
}
|
|
}
|
|
|
|
// The root project doesn't produce a JAR.
|
|
tasks["jar"].enabled = false
|
|
|
|
// ==== Javadoc ====
|
|
project.afterEvaluate {
|
|
tasks.javadoc {
|
|
title = "Smithy API ${version}"
|
|
setDestinationDir(file("${project.buildDir}/docs/javadoc/latest"))
|
|
// Build a consolidated javadoc of all subprojects.
|
|
source(project.subprojects.stream().map({
|
|
project(it.path).sourceSets.main.allJava
|
|
}).collect(Collectors.toList()))
|
|
classpath = files(project.subprojects.stream()
|
|
.map({project(it.path).sourceSets.main.compileClasspath})
|
|
.collect(Collectors.toList()))
|
|
}
|
|
}
|
|
|
|
// Disable HTML doclint to work around heading tag sequence validation
|
|
// inconsistencies between JDK15 and earlier Java versions.
|
|
allprojects {
|
|
tasks.withType(Javadoc) {
|
|
options.addStringOption('Xdoclint:-html', '-quiet')
|
|
// Fixed in JDK 12: https://bugs.openjdk.java.net/browse/JDK-8215291
|
|
// --no-module-directories does not exist in JDK 8 and is removed in 13
|
|
if (JavaVersion.current().isJava9()
|
|
|| JavaVersion.current().isJava10()
|
|
|| JavaVersion.current().isJava11()) {
|
|
options.addBooleanOption('-no-module-directories', true)
|
|
}
|
|
}
|
|
}
|
|
|
|
// We're using JReleaser in the smithy-cli subproject, so we want to have a flag to control
|
|
// which JReleaser configuration to use to prevent conflicts
|
|
if (project.hasProperty("release.main")) {
|
|
apply plugin: 'org.jreleaser'
|
|
|
|
jreleaser {
|
|
dryrun = false
|
|
|
|
// Used for creating and pushing the version tag, but this configuration ensures that
|
|
// an actual GitHub release isn't created (since the CLI release does that)
|
|
release {
|
|
github {
|
|
skipRelease = true
|
|
tagName = '{{projectVersion}}'
|
|
}
|
|
}
|
|
|
|
// Used to announce a release to configured announcers.
|
|
// https://jreleaser.org/guide/latest/reference/announce/index.html
|
|
announce {
|
|
active = "NEVER"
|
|
}
|
|
|
|
// Signing configuration.
|
|
// https://jreleaser.org/guide/latest/reference/signing.html
|
|
signing {
|
|
active = "ALWAYS"
|
|
armored = true
|
|
}
|
|
|
|
// Configuration for deploying to Maven Central.
|
|
// https://jreleaser.org/guide/latest/examples/maven/maven-central.html#_gradle
|
|
deploy {
|
|
maven {
|
|
nexus2 {
|
|
'maven-central' {
|
|
active = "ALWAYS"
|
|
url = "https://aws.oss.sonatype.org/service/local"
|
|
snapshotUrl = "https://aws.oss.sonatype.org/content/repositories/snapshots"
|
|
closeRepository = true
|
|
releaseRepository = true
|
|
stagingRepository(stagingDirectory.get().toString())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|