import java.nio.file.Files import org.gradle.util.GradleVersion apply plugin: 'groovy' /* * Build checks */ String minimumGradleVersion = file('src/main/resources/minimumGradleVersion').text.trim() if (GradleVersion.current() < GradleVersion.version(minimumGradleVersion)) { throw new GradleException("Gradle ${minimumGradleVersion}+ is required to build opensearch-hadoop") } if (JavaVersion.current() < JavaVersion.VERSION_11) { throw new GradleException('At least Java 11 is required to use opensearch gradle tools') } /* * Configure Project Versions */ boolean localRepo = project.getProperties().containsKey("localRepo") Properties props = new Properties() props.load(project.file('opensearch-hadoop-version.properties').newDataInputStream()) String opensearchHadoopVersion = props.getProperty('opensearch_hadoop') String opensearchVersion = props.getProperty('opensearch') String buildToolsVersion = props.getProperty('build-tools') // determine if we're building a prerelease or candidate (alphaX/betaX/rcX) String qualifier = System.getProperty("build.version_qualifier", "") if (qualifier.isEmpty() == false) { if (qualifier.matches("(alpha|beta|rc)\\d+") == false) { throw new IllegalStateException("Invalid qualifier: " + qualifier) } opensearchHadoopVersion += "-" + qualifier opensearchVersion += "-" + qualifier buildToolsVersion += "-" + qualifier } // determine if we're building a snapshot or not (by default we will be) boolean snapshot = "true".equals(System.getProperty("build.snapshot", "true")) if (snapshot) { // we update the version property to reflect if we are building a snapshot or a release build opensearchHadoopVersion += "-SNAPSHOT" opensearchVersion += "-SNAPSHOT" buildToolsVersion += "-SNAPSHOT" } props.put("opensearch_hadoop", opensearchHadoopVersion) props.put("opensearch", opensearchVersion) props.put("build-tools", buildToolsVersion) repositories { gradlePluginPortal() mavenCentral() // For OpenSearch snapshots. if (localRepo) { // For some reason the root dirs all point to the buildSrc folder. The local Repo will be one above that. flatDir { dirs new File(project.rootDir, "../localRepo") } } else if (snapshot) { maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" } } else { maven { url "https://plugins.gradle.org/m2/" } } } dependencies { compileOnly gradleApi() compileOnly localGroovy() // Required for dependency licenses task implementation 'org.apache.rat:apache-rat:0.15' implementation 'commons-codec:commons-codec:1.15' if (localRepo) { implementation name: "build-tools-${buildToolsVersion}" } else { implementation group: 'org.opensearch.gradle', name: 'build-tools', version: buildToolsVersion } } // write the updated properties to a temp property file File tempPropertiesFile = new File(project.buildDir, "opensearch-hadoop-version.properties") task writeVersionProperties { inputs.properties(props) outputs.file(tempPropertiesFile) doLast { OutputStream stream = Files.newOutputStream(tempPropertiesFile.toPath()) try { props.store(stream, "UTF-8") } finally { stream.close() } } } // copy the saved property file to the resources dir processResources { dependsOn writeVersionProperties from tempPropertiesFile }