|
| 1 | +/* |
| 2 | + * This file is part of ReadonlyREST. |
| 3 | + * |
| 4 | + * ReadonlyREST is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * ReadonlyREST is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with ReadonlyREST. If not, see http://www.gnu.org/licenses/ |
| 16 | + */ |
| 17 | +import org.gradle.crypto.checksum.Checksum |
| 18 | + |
| 19 | +plugins { |
| 20 | + id 'org.gradle.crypto.checksum' |
| 21 | + id "readonlyrest.plugin-common-conventions" |
| 22 | +} |
| 23 | + |
| 24 | +def pluginFullName = pluginName + '-' + version |
| 25 | +def projectJavaLanguageVersion = JavaLanguageVersion.of(21) |
| 26 | +def moduleEsVersion = project.property('esVersion') != null ? project.property('esVersion') : project.property('latestSupportedEsVersion') |
| 27 | +def releaseDockerImageLatest = 'beshultd/elasticsearch-readonlyrest:' + moduleEsVersion + '-ror-latest' |
| 28 | +def releaseDockerImageVersion = 'beshultd/elasticsearch-readonlyrest:' + moduleEsVersion + '-ror-' + pluginVersion |
| 29 | +def preBuildDockerImageVersion = 'beshultd/elasticsearch-readonlyrest-dev:' + moduleEsVersion + '-ror-' + pluginVersion |
| 30 | + |
| 31 | +java { |
| 32 | + toolchain { |
| 33 | + languageVersion = projectJavaLanguageVersion |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +dependencies { |
| 38 | + implementation project(path: ':core') |
| 39 | + implementation project(path: ':ror-tools', configuration: 'shadow') |
| 40 | + implementation project(path: ':ror-tools-core') |
| 41 | + implementation group: 'org.elasticsearch', name: 'elasticsearch' , version: moduleEsVersion |
| 42 | + implementation group: 'org.elasticsearch.client', name: 'elasticsearch-rest-client', version: moduleEsVersion |
| 43 | + implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13' |
| 44 | + implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.1' |
| 45 | + compileOnly group: 'org.locationtech.spatial4j', name: 'spatial4j', version: '0.7' |
| 46 | + // if you don't have this dependency in local maven, please run publishToMavenLocal task first |
| 47 | + compileOnly group: 'org.elasticsearch.plugin', name: 'transport-netty4', version: moduleEsVersion |
| 48 | +} |
| 49 | + |
| 50 | +configurations { |
| 51 | + wagon |
| 52 | + distJars { |
| 53 | + exclude group: 'org.elasticsearch' |
| 54 | + exclude group: 'lucene-core' |
| 55 | + exclude module: 'log4j-api' |
| 56 | + exclude module: 'log4j-core' |
| 57 | + exclude group: 'lucene-analyzers-common' |
| 58 | + exclude group: 'org.apache.commons' |
| 59 | + exclude group: 'org.yaml' |
| 60 | + exclude group: 'com.fasterxml.jackson.core', module: 'jackson-core' |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +tasks.register('cleanOldData') { |
| 65 | + doLast { |
| 66 | + delete 'build/tmp/' + pluginFullName |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +tasks.register('jarHellCheck', JavaExec) { |
| 71 | + outputs.upToDateWhen { false } |
| 72 | + mainClass.set("org.elasticsearch.jdk.JarHell") |
| 73 | + classpath = project.sourceSets.main.compileClasspath.filter { it.exists() } |
| 74 | + javaLauncher = javaToolchains.launcherFor { |
| 75 | + languageVersion = projectJavaLanguageVersion |
| 76 | + } |
| 77 | +} |
| 78 | + |
| 79 | +tasks.register('resolvePluginDescriptorTemplate', Copy) { |
| 80 | + outputs.upToDateWhen { false } |
| 81 | + from './plugin-metadata' |
| 82 | + into 'build/tmp/' + pluginFullName |
| 83 | + expand([ |
| 84 | + 'descriptor': [ |
| 85 | + 'name' : pluginName, |
| 86 | + 'pluginVersion': pluginVersion, |
| 87 | + 'esVersion' : moduleEsVersion |
| 88 | + ] |
| 89 | + ]) |
| 90 | +} |
| 91 | + |
| 92 | +tasks.register('buildRorPluginZip') { |
| 93 | + dependsOn(packageRorPlugin, createRorPluginChecksums) |
| 94 | +} |
| 95 | + |
| 96 | +tasks.register('packageRorPlugin', Zip) { |
| 97 | + dependsOn(cleanOldData, jarHellCheck, toJar, resolvePluginDescriptorTemplate) |
| 98 | + outputs.upToDateWhen { false } |
| 99 | + archivesBaseName = pluginName |
| 100 | + into('.') { |
| 101 | + from configurations.distJars.filter { x -> !x.name.contains('spatial4j') && !x.name.contains('jts') } |
| 102 | + from 'build/libs/' + pluginFullName + '.jar' |
| 103 | + from 'build/tmp/' + pluginFullName |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +tasks.register('createRorPluginChecksums', Checksum) { |
| 108 | + dependsOn(packageRorPlugin) |
| 109 | + def distributionsDir = layout.buildDirectory.dir("distributions") |
| 110 | + |
| 111 | + outputs.upToDateWhen { false } |
| 112 | + inputFiles.setFrom(packageRorPlugin.archiveFile) |
| 113 | + outputDirectory.set(distributionsDir) |
| 114 | + checksumAlgorithm.set(Checksum.Algorithm.SHA512) |
| 115 | +} |
| 116 | + |
| 117 | +tasks.register('uploadRorPluginToS3', Exec) { |
| 118 | + dependsOn(packageRorPlugin, createRorPluginChecksums) |
| 119 | + |
| 120 | + def distributionsDir = layout.buildDirectory.get().asFile.path + "/distributions" |
| 121 | + def pluginFileZip = distributionsDir + "/" + pluginFullName + ".zip" |
| 122 | + def pluginSha1 = distributionsDir + "/" + pluginFullName + ".zip.sha1" |
| 123 | + def pluginSha512 = distributionsDir + "/" + pluginFullName + ".zip.sha512" |
| 124 | + def targetS3Dir = "build/" + pluginVersion + "/" |
| 125 | + |
| 126 | + commandLine '../ci/upload-files-to-s3.sh', pluginFileZip, pluginSha512, pluginSha1, targetS3Dir |
| 127 | +} |
| 128 | + |
| 129 | +tasks.register('prepareDockerImageFiles', Copy) { |
| 130 | + dependsOn packageRorPlugin |
| 131 | + outputs.upToDateWhen { false } |
| 132 | + |
| 133 | + from layout.projectDirectory.file("Dockerfile") |
| 134 | + from layout.buildDirectory.file("distributions/" + pluginFullName + ".zip") |
| 135 | + from rootProject.files("docker-image") |
| 136 | + |
| 137 | + into layout.buildDirectory.dir("docker-image") |
| 138 | +} |
| 139 | + |
| 140 | +tasks.register('pushRorDockerImage', Exec) { |
| 141 | + dependsOn('packageRorPlugin', 'prepareDockerImageFiles', 'prepareMultiplatformBuilder') |
| 142 | + group 'docker' |
| 143 | + executable 'docker' |
| 144 | + workingDir 'build/docker-image' |
| 145 | + args = [ |
| 146 | + 'buildx', 'build', '--platform', 'linux/amd64,linux/arm64', |
| 147 | + '--build-arg', 'ROR_VERSION=' + pluginVersion, '--build-arg', "ES_VERSION=" + project.properties['esVersion'], |
| 148 | + '-t', releaseDockerImageLatest, '-t', releaseDockerImageVersion, |
| 149 | + '--push', '.' |
| 150 | + ] |
| 151 | +} |
| 152 | + |
| 153 | +tasks.register('pushRorPreBuildDockerImage', Exec) { |
| 154 | + dependsOn('packageRorPlugin', 'prepareDockerImageFiles', 'prepareMultiplatformBuilder') |
| 155 | + group 'docker' |
| 156 | + executable 'docker' |
| 157 | + workingDir 'build/docker-image' |
| 158 | + args = [ |
| 159 | + 'buildx', 'build', '--platform', 'linux/amd64,linux/arm64', |
| 160 | + '--build-arg', 'ROR_VERSION=' + pluginVersion, '--build-arg', "ES_VERSION=" + project.properties['esVersion'], |
| 161 | + '-t', preBuildDockerImageVersion, |
| 162 | + '--push', '.' |
| 163 | + ] |
| 164 | +} |
| 165 | + |
| 166 | +tasks.register('localRorDockerImage', Exec) { |
| 167 | + // we prepare docker image for local architecture - the image is loaded to local registry |
| 168 | + dependsOn('packageRorPlugin', 'prepareDockerImageFiles') |
| 169 | + group 'docker' |
| 170 | + executable 'docker' |
| 171 | + workingDir 'build/docker-image' |
| 172 | + args = [ |
| 173 | + 'buildx', 'build', |
| 174 | + '--build-arg', 'ROR_VERSION=' + pluginVersion, '--build-arg', "ES_VERSION=" + project.properties['esVersion'], |
| 175 | + '-t', releaseDockerImageVersion, |
| 176 | + '--load', '.' |
| 177 | + ] |
| 178 | +} |
0 commit comments