import java.net.HttpURLConnection import org.elasticsearch.gradle.VersionProperties apply plugin: 'distribution' ext.version = VersionProperties.elasticsearch // This project pulls a snapshot version of the ML cpp artifacts and sets that as the artifact // for this project so it can be used with dependency substitution. void getZip(File snapshotZip) { String zipUrl = "http://prelert-artifacts.s3.amazonaws.com/maven/org/elasticsearch/ml/ml-cpp/${version}/ml-cpp-${version}.zip" File snapshotMd5 = new File(snapshotZip.toString() + '.md5') HttpURLConnection conn = (HttpURLConnection) new URL(zipUrl).openConnection(); // do a HEAD first to check the zip hash against the local file conn.setRequestMethod('HEAD'); if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { throw new GradleException('ML cpp snapshot does not exist') } String remoteMd5 = conn.getHeaderField('ETag') if (snapshotZip.exists()) { // do a HEAD first to check the zip hash against the local file String localMd5 = snapshotMd5.getText('UTF-8') if (remoteMd5.equals(localMd5)) { logger.info('Using cached ML snapshot') return } } snapshotZip.bytes = new URL(zipUrl).bytes snapshotMd5.setText(remoteMd5, 'UTF-8') } File snapshotZip = new File(projectDir, ".cache/ml-cpp-${version}.zip") task downloadMachineLearningSnapshot { onlyIf { // skip if machine-learning-cpp is being built locally findProject(':machine-learning-cpp') == null && // skip for offline builds - just rely on the artifact already having been downloaded before here project.gradle.startParameter.isOffline() == false } doFirst { snapshotZip.parentFile.mkdirs() getZip(snapshotZip) } } artifacts { 'default' file: snapshotZip, name: 'ml-cpp', type: 'zip', builtBy: downloadMachineLearningSnapshot }