/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ buildscript { ext { // Detect version from version.properties and align it with the build settings def build = new Properties() file("version.properties").withInputStream { build.load(it) } var isSnapshot = System.getProperty("build.snapshot", "true") buildVersion = build.getProperty("version") if (isSnapshot.toBoolean() && !buildVersion.endsWith("SNAPSHOT")) { buildVersion = buildVersion + "-SNAPSHOT" } else if (!isSnapshot && buildVersion.endsWith("SNAPSHOT")) { throw GradleException("Expecting release (non-SNAPSHOT) build but version is not set accordingly: " + buildVersion) } // Check if tag release version (if provided) matches the version from build settings tagVersion = System.getProperty("build.version", buildVersion) if (!buildVersion.equals(tagVersion)) { throw GradleException("The tagged version " + tagVersion + " does not match the build version " + buildVersion) } } repositories { mavenLocal() mavenCentral() maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" } } dependencies { classpath group: 'com.google.guava', name: 'guava', version: '30.1-jre' } } plugins { id 'java' id 'application' id 'java-library' id 'maven-publish' id 'com.diffplug.spotless' version '5.11.0' id 'com.github.spotbugs' version '5.0.13' } spotbugsMain { excludeFilter = file("checkstyle/findbugs-exclude.xml") effort = 'max' ignoreFailures = true // TODO: Set this to false later as they are too many warnings to be fixed. reports { xml.enabled = false html.enabled = true } } spotbugsTest { ignoreFailures = true } allprojects { repositories { mavenLocal() mavenCentral() maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" } maven { url "https://plugins.gradle.org/m2/" } } group 'org.opensearch.performanceanalyzer.commons' version = buildVersion } targetCompatibility = JavaVersion.VERSION_11 sourceCompatibility = JavaVersion.VERSION_11 apply plugin: 'java' apply plugin: 'jacoco' apply plugin: 'signing' apply plugin: 'maven-publish' apply from: 'build-tools/coverage.gradle' dependencies { if (JavaVersion.current() <= JavaVersion.VERSION_1_8) { implementation files("${System.properties['java.home']}/../lib/tools.jar") } def jacksonVersion = "2.15.1" def jacksonDataBindVersion = "2.14.1" def junitVersion = "4.13.1" def log4jVersion = "2.17.1" implementation "org.jooq:jooq:3.10.8" implementation "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}" implementation "com.fasterxml.jackson.core:jackson-databind:${jacksonDataBindVersion}" implementation 'com.google.guava:guava:31.1-jre' implementation 'com.google.code.gson:gson:2.9.0' implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: "${log4jVersion}" implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: "${log4jVersion}" testImplementation group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.0' testImplementation group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.0' testImplementation group: 'org.mockito', name: 'mockito-core', version: '2.23.0' testImplementation group: 'org.powermock', name: 'powermock-core', version: '2.0.0' testImplementation group: 'org.powermock', name: 'powermock-api-support', version: '2.0.0' testImplementation group: 'org.powermock', name: 'powermock-module-junit4-common', version: '2.0.0' testImplementation group: 'org.javassist', name: 'javassist', version: '3.24.0-GA' testImplementation group: 'org.powermock', name: 'powermock-reflect', version: '2.0.0' testImplementation group: 'net.bytebuddy', name: 'byte-buddy', version: '1.9.3' testImplementation group: 'org.objenesis', name: 'objenesis', version: '3.0.1' testImplementation group: 'org.hamcrest', name: 'hamcrest-library', version: '2.1' testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.1' testImplementation group: 'junit', name: 'junit', version: "${junitVersion}" } //TODO: remove once spotbugs upgrades to 4.7.4 configurations.each { c -> c.resolutionStrategy.dependencySubstitution { all { DependencySubstitution dependency -> if (dependency.requested.group == 'org.apache.bcel') { dependency.useTarget 'org.apache.bcel:bcel:6.6.1' } } } } compileJava { dependsOn spotlessApply JavaVersion targetVersion = JavaVersion.toVersion(targetCompatibility); if (targetVersion.isJava9Compatible()) { options.compilerArgs += ["--add-exports", "jdk.attach/sun.tools.attach=ALL-UNNAMED"] options.compilerArgs += ["--add-exports", "jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED"] } } test { testLogging { exceptionFormat "full" events "skipped", "passed", "failed", "started" showStandardStreams true } } distributions { main { contents { eachFile { it.path = it.path.replace("-$version/", '/') } } } } spotless { java { licenseHeaderFile(file('license-header')) googleJavaFormat('1.12.0').aosp() importOrder() removeUnusedImports() trimTrailingWhitespace() endWithNewline() // add support for spotless:off and spotless:on tags to exclude sections of code toggleOffOn() } } tasks.withType(Test) { jvmArgs('-Dopensearch.path.conf=src/test/resources/config') jvmArgs('--add-opens=java.base/sun.nio.fs=ALL-UNNAMED') jvmArgs('--add-opens=java.base/java.io=ALL-UNNAMED') jvmArgs('--add-opens=java.base/java.nio.file=ALL-UNNAMED') jvmArgs('--add-opens=java.base/java.lang=ALL-UNNAMED') jvmArgs('--add-opens=java.base/java.util=ALL-UNNAMED') jvmArgs('--add-opens=java.xml/jdk.xml.internal=ALL-UNNAMED') } javadoc { exclude 'org/opensearch/performanceanalyzer/commons/jvm/**' } task sourcesJar(type: Jar) { archiveClassifier.set("sources") from sourceSets.main.allJava } task javadocJar(type: Jar) { archiveClassifier.set("javadoc") from sourceSets.main.allJava dependsOn javadoc } publishing { publications { create(MavenPublication) { groupId = 'org.opensearch' artifactId = 'performance-analyzer-commons' from(components["java"]) artifact sourcesJar artifact javadocJar pom { name = "OpenSearch Performance Analyzer Commons" packaging = "jar" url = "https://github.com/opensearch-project/performance-analyzer-commons" description = "OpenSearch Performance Analyzer Commons Library" scm { connection = "scm:git@github.com:opensearch-project/performance-analyzer-commons.git" developerConnection = "scm:git@github.com:opensearch-project/performance-analyzer-commons.git" url = "git@github.com:opensearch-project/performance-analyzer-commons.git" } licenses { license { name = "The Apache License, Version 2.0" url = "http://www.apache.org/licenses/LICENSE-2.0.txt" } } developers { developer { name = "OpenSearch" url = "https://github.com/opensearch-project/performance-analyzer-commons" } } } } } repositories { if (buildVersion.toString().endsWith("SNAPSHOT")) { maven { name = "Snapshots" url = "https://aws.oss.sonatype.org/content/repositories/snapshots/" credentials { username = System.getenv("SONATYPE_USERNAME") password = System.getenv("SONATYPE_PASSWORD") } } } maven { name = "localRepo" url = "${rootProject.buildDir}/repository" } } gradle.startParameter.setShowStacktrace(ShowStacktrace.ALWAYS) gradle.startParameter.setLogLevel(LogLevel.DEBUG) }