plugins { id 'java' id 'com.github.spotbugs' version '5.0.13' id 'checkstyle' id 'jacoco' id 'com.github.hierynomus.license' version '0.16.1' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.kordamp.gradle.markdown' version '2.2.0' id "de.undercouch.download" version "5.3.0" id 'io.franzbecker.gradle-lombok' version '5.0.0' id 'java-test-fixtures' id 'maven-publish' id 'signing' } group 'software.amazon.documentdb.jdbc' version project.hasProperty("BETA_VERSION") ? "${project.MAJOR_VERSION}.${project.MINOR_VERSION}.${project.PATCH_VERSION}-beta.${project.BETA_VERSION}" : "${project.MAJOR_VERSION}.${project.MINOR_VERSION}.${project.PATCH_VERSION}" description 'documentdb-jdbc-driver' tasks.register('licenseAndNotice') { copy { from "${rootDir}/LICENSE" into 'src/main/resources' } copy { from "${rootDir}/NOTICE" into 'src/main/resources' } } java { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 withJavadocJar() withSourcesJar() } tasks.withType(JavaCompile) { options.compilerArgs << '-Xlint:unchecked' options.deprecation = true options.encoding 'UTF-8' } // Silently agree to build scan terms. if (hasProperty('buildScan')) { buildScan { termsOfServiceUrl = 'https://gradle.com/terms-of-service' termsOfServiceAgree = 'yes' } } jar { manifest { attributes( 'Implementation-Version': archiveVersion.get(), 'Main-Class': 'software.amazon.documentdb.jdbc.DocumentDbMain') } } shadowJar { dependsOn('licenseAndNotice') // Exclude driver unnecessary classes. exclude 'org/apache/calcite/jdbc/Driver*' exclude 'org/apache/calcite/avatica/remote/Driver*' exclude 'org/apache/commons/dbcp2/PoolingDriver*' // NOTE: DO NOT relocate 'javax', 'org.apache.log4j', 'org.sl4j', 'org.codehaus' // Relocate (shadow) the following packages. relocate 'com.esri', 'shadow.com.esri' relocate 'com.fasterxml', 'shadow.com.fasterxml' relocate 'com.google', 'shadow.com.google' relocate 'com.jayway', 'shadow.com.jayway' relocate 'com.jcraft', 'shadow.com.jcraft' relocate 'com.mongodb', 'shadow.com.mongodb' relocate 'com.yahoo', 'shadow.com.yahoo' relocate 'codegen', 'shadow.codegen' relocate 'net', 'shadow.net' relocate 'nl', 'shadow.nl' relocate 'org.apache.calcite', 'shadow.org.apache.calcite' relocate 'org.apache.commons', 'shadow.org.apache.commons' relocate 'org.apache.http', 'shadow.org.apache.http' relocate 'org.apache.logging', 'shadow.org.apache.logging' relocate 'org.apiguardian', 'shadow.org.apiguardian' relocate 'org.bson', 'shadow.org.bson' relocate 'org.checkerframework', 'shadow.org.checkerframework' relocate 'org.mongodb', 'shadow.org.mongodb' relocate 'org.objectweb', 'shadow.org.objectweb' relocate 'org.pentaho', 'shadow.org.pentaho' relocate 'org.yaml', 'shadow.org.yaml' // Remove any unused dependencies (excluding Calcite) minimize { exclude(dependency('org.apache.calcite::')) exclude(dependency('org.slf4j.*::')) exclude(dependency('com.github.mwiede::')) } } artifacts { archives shadowJar archives sourcesJar archives javadocJar } test { useJUnitPlatform { if (project.hasProperty('runRemoteIntegrationTests') && project.property('runRemoteIntegrationTests') == 'true') { // Ensure to match the enumeration name exactly from DocumentDbTestEnvironmentType. environment "CONFIGURED_ENVIRONMENTS", "MONGODB40_FLAPDOODLE,DOCUMENTDB40_SSH_TUNNEL" excludeTags 'local-integration' } else { // Ensure to match the enumeration name exactly from DocumentDbTestEnvironmentType. environment "CONFIGURED_ENVIRONMENTS", "MONGODB40_FLAPDOODLE" excludeTags 'remote-integration' } } } /** * CheckStyle Plugin */ apply plugin: 'checkstyle' checkstyle { toolVersion '8.37' configFile file("config/checkstyle/checkstyle-rules.xml") ignoreFailures = false } checkstyleMain { source = 'src/main/java' } checkstyleTest { source = 'src/test/java' } /** * SpotBugs Plugin */ spotbugs { showStackTraces = false reportsDir = file("$buildDir/reports/spotbugs") ignoreFailures = false excludeFilter = file("config/spotbugs/spotbugs-exclude.xml") } spotbugsMain { // Configure HTML report reports { xml { required.set(true) destination = file("$buildDir/reports/spotbugs/main.xml") } html { required.set(true) destination = file("$buildDir/reports/spotbugs/main.html") } } } spotbugsTest { // Configure HTML report reports { xml { required.set(true) destination = file("$buildDir/reports/spotbugs/test.xml") } html { required.set(true) destination = file("$buildDir/reports/spotbugs/test.html") } } } task checkSpotBugsMainReport { doLast { def xmlReport = spotbugsMain.reports.getByName("xml") def slurped = new groovy.xml.XmlSlurper().parse(xmlReport.destination) def bugsFound = slurped.BugInstance.size() slurped.BugInstance.each { println "SpotBugs Error" println "\tShort Message:\t\t${it.ShortMessage}" println "\tLong Message:\t\t${it.LongMessage}" println "\tSource of Error:\t${it.SourceLine.Message}" } if (bugsFound > 0) { throw new Exception("Encountered SpotBugs errors, see above.") } } } task checkSpotBugsTestReport { doLast { def xmlReport = spotbugsTest.reports.getByName("xml") def slurped = new XmlSlurper().parse(xmlReport.destination) def bugsFound = slurped.BugInstance.size() slurped.BugInstance.each { println "SpotBugs Error" println "\tShort Message:\t\t${it.ShortMessage}" println "\tLong Message:\t\t${it.LongMessage}" println "\tSource of Error:\t${it.SourceLine.Message}" } if (bugsFound > 0) { //TODO Temporary ignoring, as dedicated set of rules should be defined //throw new Exception("Encountered SpotBugs errors, see above.") } } } spotbugsMain.finalizedBy checkSpotBugsMainReport spotbugsTest.finalizedBy checkSpotBugsTestReport /** * JaCoCo Plugin */ test { jacoco { excludes = ['org/codehaus/**', 'org.codehaus.*'] } } jacoco { toolVersion = "0.8.8" } jacocoTestReport { reports { html.required = true csv.required = true } afterEvaluate { classDirectories.setFrom(files(classDirectories.files.collect { project.logger.info('it' + it) fileTree(dir: it, exclude: ['**/resources/**', '**janino**', '**commons**']) })) } } test.finalizedBy(project.tasks.jacocoTestReport) jacocoTestCoverageVerification { violationRules { rule { element = 'CLASS' excludes = ['org.codehaus.*'] limit { counter = 'LINE' minimum = 0.00 } limit { counter = 'BRANCH' minimum = 0.00 } } } afterEvaluate { classDirectories.setFrom(files(classDirectories.files.collect { fileTree(dir: it, exclude: ['org/codehaus/**']) })) } } check.dependsOn jacocoTestCoverageVerification jacocoTestCoverageVerification.dependsOn jacocoTestReport /** * License Plugin */ license { skipExistingHeaders = true header = project.file('license-header.txt') exclude "**/*.properties" headerDefinitions { slash_star_with_space { firstLine = '/*' endLine = ' *\n */\n' beforeEachLine = ' * ' firstLineDetectionPattern = '/\\*' lastLineDetectionPattern = ' \\*\n \\*/\n' } } mapping { java = 'slash_star_with_space' } } /** * Write driver version data to properties file under base project. */ task writeProperties(type: WriteProperties) { outputFile("$projectDir/src/main/resources/project.properties") property("driver.major.version", MAJOR_VERSION) property("driver.minor.version", MINOR_VERSION) property("driver.full.version", project.version) property("default.application.name", APPLICATION_NAME) } import io.franzbecker.gradle.lombok.task.DelombokTask task delombok(type: DelombokTask, dependsOn: compileJava) { ext.outputDir = file("$buildDir/delombok") outputs.dir(outputDir) sourceSets.main.java.srcDirs.each { inputs.dir(it) args(it, "-d", outputDir) } } javadoc { dependsOn delombok source = delombok.outputDir } processResources { from(writeProperties) duplicatesStrategy(DuplicatesStrategy.INCLUDE) } repositories { mavenCentral() } dependencies { implementation group: 'commons-cli', name: 'commons-cli', version: '1.5.0' implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.14.1' implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-guava', version: '2.14.1' implementation group: 'com.google.guava', name: 'guava', version: '31.1-jre' implementation group: 'org.slf4j', name: 'slf4j-log4j12', version: '2.0.6' implementation group: 'org.apache.commons', name: 'commons-text', version: '1.10.0' implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0' implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.19.0' implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.19.0' implementation group: 'org.mongodb', name: 'mongodb-driver-sync', version: '4.8.1' implementation group: 'com.github.mwiede', name: 'jsch', version: '0.2.6' implementation group: 'org.apache.calcite', name: 'calcite-core', version: '1.32.0' implementation group: 'commons-beanutils', name: 'commons-beanutils', version: '1.9.4' implementation 'io.github.hakky54:sslcontext-kickstart:7.4.9' compileOnly group: 'org.immutables', name: 'value', version: '2.9.3' compileOnly group: 'com.puppycrawl.tools', name: 'checkstyle', version: '10.6.0' compileOnly 'org.projectlombok:lombok:1.18.24' annotationProcessor 'org.projectlombok:lombok:1.18.24' testCompileOnly group: 'com.google.code.findbugs', name: 'annotations', version: '3.0.1' testCompileOnly group: 'com.google.code.findbugs', name: 'annotations', version: '3.0.1' testCompileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.24' testAnnotationProcessor group: 'org.projectlombok', name: 'lombok', version: '1.18.24' testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.9.1' testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.9.1' testImplementation group: 'org.mockito', name: 'mockito-core', version: '4.11.0' testRuntimeOnly group: 'de.flapdoodle.embed', name: 'de.flapdoodle.embed.mongo', version: '3.5.3' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-api:5.9.1' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.9.1' spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.12.0' testFixturesCompileOnly group: 'de.flapdoodle.embed', name: 'de.flapdoodle.embed.mongo', version: '3.5.3' testFixturesCompileOnly 'org.junit.jupiter:junit-jupiter-api:5.9.1' testFixturesImplementation group: 'com.google.guava', name: 'guava', version: '29.0-jre' testFixturesImplementation group: 'org.mongodb', name: 'mongodb-driver-sync', version: '4.8.1' testFixturesImplementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.17.2' testFixturesImplementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.17.2' } publishing { publications { mavenJava(MavenPublication) { from components.java pom { name = 'Amazon DocumentDB JDBC Driver' groupId = project.group artifactId = project.name version = version description = 'The JDBC driver for the Amazon DocumentDB managed document database provides an SQL-relational interface for developers and BI tool users.' url = 'https://github.com/aws/amazon-documentdb-jdbc-driver' licenses { license { name = 'Apache License, Version 2.0' url = 'https://aws.amazon.com/apache2.0' distribution = 'repo' } } scm { connection = 'scm:git:https://github.com/aws/amazon-documentdb-jdbc-driver.git' developerConnection = 'scm:git:git@github.com:aws/amazon-documentdb-jdbc-driver.git' url = 'https://github.com/aws/amazon-documentdb-jdbc-driver' } inceptionYear = '2021' developers { developer { id = 'amazonwebservices' organization { name = 'Amazon Web Services' } organizationUrl = 'https://aws.amazon.com' } } } } } } signing { sign publishing.publications.mavenJava }