/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ buildscript { ext { opensearch_group = "org.opensearch" opensearch_version = System.getProperty("opensearch.version", "3.0.0-SNAPSHOT") isSnapshot = "true" == System.getProperty("build.snapshot", "true") buildVersionQualifier = System.getProperty("build.version_qualifier", "") kotlin_version = System.getProperty("kotlin.version", "1.8.21") } repositories { mavenLocal() mavenCentral() maven { url "https://plugins.gradle.org/m2/" } maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" } } dependencies { classpath "${opensearch_group}.gradle:build-tools:${opensearch_version}" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlin_version}" classpath "org.jetbrains.kotlin:kotlin-allopen:${kotlin_version}" // classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.20.0-RC1" } } plugins { id 'java-library' id 'maven-publish' id 'com.diffplug.spotless' version '6.18.0' } repositories { mavenLocal() mavenCentral() maven { url "https://plugins.gradle.org/m2/" } maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" } } allprojects { group 'org.opensearch.commons' version = opensearch_version.tokenize('-')[0] + '.0' if (buildVersionQualifier) { version += "-${buildVersionQualifier}" } if (isSnapshot) { version += "-SNAPSHOT" } } targetCompatibility = JavaVersion.VERSION_11 sourceCompatibility = JavaVersion.VERSION_11 apply plugin: 'java' apply plugin: 'jacoco' apply plugin: 'signing' apply plugin: 'maven-publish' apply plugin: 'com.github.johnrengelman.shadow' // apply plugin: 'io.gitlab.arturbosch.detekt' apply plugin: 'org.jetbrains.kotlin.jvm' apply plugin: 'org.jetbrains.kotlin.plugin.allopen' apply plugin: 'opensearch.repositories' apply from: 'build-tools/opensearchplugin-coverage.gradle' configurations { ktlint } dependencies { compileOnly "org.opensearch.client:opensearch-rest-high-level-client:${opensearch_version}" compileOnly "org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}" compileOnly "org.jetbrains.kotlin:kotlin-stdlib-common:${kotlin_version}" compileOnly "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3" // ${kotlin_version} does not work for coroutines compileOnly "com.cronutils:cron-utils:9.1.6" compileOnly "commons-validator:commons-validator:1.7" testImplementation "org.opensearch.test:framework:${opensearch_version}" testImplementation "org.jetbrains.kotlin:kotlin-test:${kotlin_version}" testImplementation "org.mockito:mockito-core:3.10.0" testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2' testImplementation 'org.mockito:mockito-junit-jupiter:3.10.0' testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0" testImplementation "com.cronutils:cron-utils:9.1.6" testImplementation "commons-validator:commons-validator:1.7" testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2' ktlint "com.pinterest:ktlint:0.44.0" } test { useJUnitPlatform() testLogging { exceptionFormat "full" events "skipped", "passed", "failed" // "started" showStandardStreams true } } spotless { java { removeUnusedImports() importOrder 'java', 'javax', 'org', 'com' licenseHeaderFile 'spotless.license.java' eclipse().configFile rootProject.file('.eclipseformat.xml') } } // TODO: enable detekt only when snakeyaml vulnerability is fixed /*detekt { config = files("detekt.yml") buildUponDefaultConfig = true }*/ tasks.register('ktlint', JavaExec) { description = "Check Kotlin code style." main = "com.pinterest.ktlint.Main" classpath = configurations.ktlint args "src/**/*.kt" // to generate report in checkstyle format prepend following args: // "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/ktlint.xml" // see https://github.com/pinterest/ktlint#usage for more } check.dependsOn ktlint tasks.register('ktlintFormat', JavaExec) { description = "Fix Kotlin code style deviations." classpath = configurations.ktlint // https://github.com/pinterest/ktlint/issues/1391#issuecomment-1251287020 jvmArgs "--add-opens=java.base/java.lang=ALL-UNNAMED" setProperty("mainClass", "com.pinterest.ktlint.Main") args "-F", "src/**/*.kt" } compileKotlin { kotlinOptions { freeCompilerArgs = ['-Xjsr305=strict'] jvmTarget = "11" } } compileTestKotlin { kotlinOptions { jvmTarget = "11" } } shadowJar { archiveClassifier = null } task sourcesJar(type: Jar) { archiveClassifier = 'sources' from sourceSets.main.allJava } task javadocJar(type: Jar) { archiveClassifier = 'javadoc' from javadoc.destinationDir } publishing { repositories { maven { name = 'staging' url = "${rootProject.buildDir}/local-staging-repo" } maven { name = "Snapshots" url = "https://aws.oss.sonatype.org/content/repositories/snapshots" credentials { username "$System.env.SONATYPE_USERNAME" password "$System.env.SONATYPE_PASSWORD" } } } publications { shadow(MavenPublication) { project.shadow.component(it) groupId = 'org.opensearch' artifactId = 'common-utils' artifact sourcesJar artifact javadocJar pom { name = "OpenSearch Common Utils" packaging = "jar" url = "https://github.com/opensearch-project/common-utils" description = "OpenSearch Common Utils" scm { connection = "scm:git@github.com:opensearch-project/common-utils.git" developerConnection = "scm:git@github.com:opensearch-project/common-utils.git" url = "git@github.com:opensearch-project/common-utils.git" } licenses { license { name = "The Apache License, Version 2.0" url = "http://www.apache.org/licenses/LICENSE-2.0.txt" } } developers { developer { id = "amazonwebservices" organization = "Amazon Web Services" organizationUrl = "https://aws.amazon.com" } } } } } gradle.startParameter.setShowStacktrace(ShowStacktrace.ALWAYS) gradle.startParameter.setLogLevel(LogLevel.DEBUG) } // updateVersion: Task to auto increment to the next development iteration task updateVersion { onlyIf { System.getProperty('newVersion') } doLast { ext.newVersion = System.getProperty('newVersion') println "Setting version to ${newVersion}." // String tokenization to support -SNAPSHOT // Include the required files that needs to be updated with new Version ant.replaceregexp(file:'build.gradle', match: '"opensearch.version", "\\d.*"', replace: '"opensearch.version", "' + newVersion.tokenize('-')[0] + '-SNAPSHOT"', flags:'g', byline:true) } }