build.gradle 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. /*
  2. * Licensed to Elasticsearch under one or more contributor
  3. * license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright
  5. * ownership. Elasticsearch licenses this file to you under
  6. * the Apache License, Version 2.0 (the "License"); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
  20. import org.apache.tools.ant.taskdefs.condition.Os
  21. import org.elasticsearch.gradle.BuildPlugin
  22. import org.elasticsearch.gradle.Version
  23. import org.elasticsearch.gradle.BwcVersions
  24. import org.elasticsearch.gradle.VersionProperties
  25. import org.elasticsearch.gradle.plugin.PluginBuildPlugin
  26. import org.gradle.util.GradleVersion
  27. import org.gradle.util.DistributionLocator
  28. import org.gradle.plugins.ide.eclipse.model.SourceFolder
  29. plugins {
  30. id 'com.gradle.build-scan' version '2.2.1'
  31. id 'base'
  32. }
  33. if (Boolean.valueOf(project.findProperty('org.elasticsearch.acceptScanTOS') ?: "false")) {
  34. buildScan {
  35. termsOfServiceUrl = 'https://gradle.com/terms-of-service'
  36. termsOfServiceAgree = 'yes'
  37. }
  38. }
  39. // common maven publishing configuration
  40. allprojects {
  41. group = 'org.elasticsearch'
  42. version = VersionProperties.elasticsearch
  43. description = "Elasticsearch subproject ${project.path}"
  44. }
  45. BuildPlugin.configureRepositories(project)
  46. apply plugin: 'nebula.info-scm'
  47. String licenseCommit
  48. if (VersionProperties.elasticsearch.toString().endsWith('-SNAPSHOT')) {
  49. licenseCommit = scminfo.change ?: "master" // leniency for non git builds
  50. } else {
  51. licenseCommit = "v${version}"
  52. }
  53. String elasticLicenseUrl = "https://raw.githubusercontent.com/elastic/elasticsearch/${licenseCommit}/licenses/ELASTIC-LICENSE.txt"
  54. subprojects {
  55. // Default to the apache license
  56. project.ext.licenseName = 'The Apache Software License, Version 2.0'
  57. project.ext.licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
  58. // But stick the Elastic license url in project.ext so we can get it if we need to switch to it
  59. project.ext.elasticLicenseUrl = elasticLicenseUrl
  60. // we only use maven publish to add tasks for pom generation
  61. plugins.withType(MavenPublishPlugin).whenPluginAdded {
  62. publishing {
  63. publications {
  64. // add license information to generated poms
  65. all {
  66. pom.withXml { XmlProvider xml ->
  67. Node node = xml.asNode()
  68. node.appendNode('inceptionYear', '2009')
  69. Node license = node.appendNode('licenses').appendNode('license')
  70. license.appendNode('name', project.licenseName)
  71. license.appendNode('url', project.licenseUrl)
  72. license.appendNode('distribution', 'repo')
  73. Node developer = node.appendNode('developers').appendNode('developer')
  74. developer.appendNode('name', 'Elastic')
  75. developer.appendNode('url', 'http://www.elastic.co')
  76. }
  77. }
  78. }
  79. repositories {
  80. maven {
  81. name = 'localTest'
  82. url = "${rootProject.buildDir}/local-test-repo"
  83. }
  84. }
  85. }
  86. }
  87. plugins.withType(BuildPlugin).whenPluginAdded {
  88. project.licenseFile = project.rootProject.file('licenses/APACHE-LICENSE-2.0.txt')
  89. project.noticeFile = project.rootProject.file('NOTICE.txt')
  90. }
  91. }
  92. /* Introspect all versions of ES that may be tested against for backwards
  93. * compatibility. It is *super* important that this logic is the same as the
  94. * logic in VersionUtils.java, throwing out alphas because they don't have any
  95. * backwards compatibility guarantees and only keeping the latest beta or rc
  96. * in a branch if there are only betas and rcs in the branch so we have
  97. * *something* to test against. */
  98. BwcVersions versions = new BwcVersions(file('server/src/main/java/org/elasticsearch/Version.java').readLines('UTF-8'))
  99. // build metadata from previous build, contains eg hashes for bwc builds
  100. String buildMetadataValue = System.getenv('BUILD_METADATA')
  101. if (buildMetadataValue == null) {
  102. buildMetadataValue = ''
  103. }
  104. Map<String, String> buildMetadataMap = buildMetadataValue.tokenize(';').collectEntries {
  105. def (String key, String value) = it.split('=')
  106. return [key, value]
  107. }
  108. // injecting groovy property variables into all projects
  109. allprojects {
  110. project.ext {
  111. // for ide hacks...
  112. isEclipse = System.getProperty("eclipse.launcher") != null || // Detects gradle launched from Eclipse's IDE
  113. System.getProperty("eclipse.application") != null || // Detects gradle launched from the Eclipse compiler server
  114. gradle.startParameter.taskNames.contains('eclipse') || // Detects gradle launched from the command line to do eclipse stuff
  115. gradle.startParameter.taskNames.contains('cleanEclipse')
  116. isIdea = System.getProperty("idea.active") != null || gradle.startParameter.taskNames.contains('idea') || gradle.startParameter.taskNames.contains('cleanIdea')
  117. // for BWC testing
  118. bwcVersions = versions
  119. buildMetadata = buildMetadataMap
  120. }
  121. }
  122. task verifyVersions {
  123. doLast {
  124. if (gradle.startParameter.isOffline()) {
  125. throw new GradleException("Must run in online mode to verify versions")
  126. }
  127. // Read the list from maven central.
  128. // Fetch the metadata an parse the xml into Version instances because it's more straight forward here
  129. // rather than bwcVersion ( VersionCollection ).
  130. new URL('https://repo1.maven.org/maven2/org/elasticsearch/elasticsearch/maven-metadata.xml').openStream().withStream { s ->
  131. bwcVersions.compareToAuthoritative(
  132. new XmlParser().parse(s)
  133. .versioning.versions.version
  134. .collect { it.text() }.findAll { it ==~ /\d+\.\d+\.\d+/ }
  135. .collect { Version.fromString(it) }
  136. )
  137. }
  138. }
  139. }
  140. /*
  141. * When adding backcompat behavior that spans major versions, temporarily
  142. * disabling the backcompat tests is necessary. This flag controls
  143. * the enabled state of every bwc task. It should be set back to true
  144. * after the backport of the backcompat code is complete.
  145. */
  146. boolean bwc_tests_enabled = true
  147. final String bwc_tests_disabled_issue = "" /* place a PR link here when committing bwc changes */
  148. if (bwc_tests_enabled == false) {
  149. if (bwc_tests_disabled_issue.isEmpty()) {
  150. throw new GradleException("bwc_tests_disabled_issue must be set when bwc_tests_enabled == false")
  151. }
  152. println "========================= WARNING ========================="
  153. println " Backwards compatibility tests are disabled!"
  154. println "See ${bwc_tests_disabled_issue}"
  155. println "==========================================================="
  156. }
  157. if (project.gradle.startParameter.taskNames.find { it.startsWith("checkPart") } != null) {
  158. // Disable BWC tests for checkPart* tasks as it's expected that this will run un it's own check
  159. bwc_tests_enabled = false
  160. }
  161. subprojects {
  162. ext.bwc_tests_enabled = bwc_tests_enabled
  163. }
  164. task verifyBwcTestsEnabled {
  165. doLast {
  166. if (bwc_tests_enabled == false) {
  167. throw new GradleException('Bwc tests are disabled. They must be re-enabled after completing backcompat behavior backporting.')
  168. }
  169. }
  170. }
  171. task branchConsistency {
  172. description 'Ensures this branch is internally consistent. For example, that versions constants match released versions.'
  173. group 'Verification'
  174. dependsOn verifyVersions, verifyBwcTestsEnabled
  175. }
  176. allprojects {
  177. // ignore missing javadocs
  178. tasks.withType(Javadoc) { Javadoc javadoc ->
  179. // the -quiet here is because of a bug in gradle, in that adding a string option
  180. // by itself is not added to the options. By adding quiet, both this option and
  181. // the "value" -quiet is added, separated by a space. This is ok since the javadoc
  182. // command already adds -quiet, so we are just duplicating it
  183. // see https://discuss.gradle.org/t/add-custom-javadoc-option-that-does-not-take-an-argument/5959
  184. javadoc.options.encoding='UTF8'
  185. javadoc.options.addStringOption('Xdoclint:all,-missing', '-quiet')
  186. }
  187. /* Sets up the dependencies that we build as part of this project but
  188. register as though they were external to resolve internally. We register
  189. them as external dependencies so the build plugin that we use can be used
  190. to build elasticsearch plugins outside of the elasticsearch source tree. */
  191. ext.projectSubstitutions = [
  192. "org.elasticsearch.gradle:build-tools:${version}": ':build-tools',
  193. "org.elasticsearch:rest-api-spec:${version}": ':rest-api-spec',
  194. "org.elasticsearch:elasticsearch:${version}": ':server',
  195. "org.elasticsearch:elasticsearch-cli:${version}": ':libs:elasticsearch-cli',
  196. "org.elasticsearch:elasticsearch-core:${version}": ':libs:core',
  197. "org.elasticsearch:elasticsearch-nio:${version}": ':libs:nio',
  198. "org.elasticsearch:elasticsearch-x-content:${version}": ':libs:x-content',
  199. "org.elasticsearch:elasticsearch-geo:${version}": ':libs:elasticsearch-geo',
  200. "org.elasticsearch:elasticsearch-secure-sm:${version}": ':libs:secure-sm',
  201. "org.elasticsearch:elasticsearch-ssl-config:${version}": ':libs:elasticsearch-ssl-config',
  202. "org.elasticsearch.client:elasticsearch-rest-client:${version}": ':client:rest',
  203. "org.elasticsearch.client:elasticsearch-rest-client-sniffer:${version}": ':client:sniffer',
  204. "org.elasticsearch.client:elasticsearch-rest-high-level-client:${version}": ':client:rest-high-level',
  205. "org.elasticsearch.client:test:${version}": ':client:test',
  206. "org.elasticsearch.client:transport:${version}": ':client:transport',
  207. "org.elasticsearch.plugin:elasticsearch-scripting-painless-spi:${version}": ':modules:lang-painless:spi',
  208. "org.elasticsearch.test:framework:${version}": ':test:framework',
  209. "org.elasticsearch.test:logger-usage:${version}": ':test:logger-usage',
  210. "org.elasticsearch.xpack.test:feature-aware:${version}": ':x-pack:test:feature-aware',
  211. // for transport client
  212. "org.elasticsearch.plugin:transport-netty4-client:${version}": ':modules:transport-netty4',
  213. "org.elasticsearch.plugin:reindex-client:${version}": ':modules:reindex',
  214. "org.elasticsearch.plugin:lang-mustache-client:${version}": ':modules:lang-mustache',
  215. "org.elasticsearch.plugin:parent-join-client:${version}": ':modules:parent-join',
  216. "org.elasticsearch.plugin:aggs-matrix-stats-client:${version}": ':modules:aggs-matrix-stats',
  217. "org.elasticsearch.plugin:percolator-client:${version}": ':modules:percolator',
  218. "org.elasticsearch.plugin:rank-eval-client:${version}": ':modules:rank-eval',
  219. // for security example plugins
  220. "org.elasticsearch.plugin:x-pack-core:${version}": ':x-pack:plugin:core',
  221. "org.elasticsearch.client:x-pack-transport:${version}": ':x-pack:transport-client'
  222. ]
  223. /*
  224. * Gradle only resolve project substitutions during dependency resolution but
  225. * we sometimes want to do the resolution at other times. This creates a
  226. * convenient method we can call to do it.
  227. */
  228. ext.dependencyToProject = { Dependency dep ->
  229. if (dep instanceof ProjectDependency) {
  230. return dep.dependencyProject
  231. } else {
  232. String substitution = projectSubstitutions.get("${dep.group}:${dep.name}:${dep.version}")
  233. if (substitution != null) {
  234. return findProject(substitution)
  235. }
  236. return null
  237. }
  238. }
  239. project.afterEvaluate {
  240. configurations.all {
  241. resolutionStrategy.dependencySubstitution { DependencySubstitutions subs ->
  242. projectSubstitutions.each { k,v ->
  243. subs.substitute(subs.module(k)).with(subs.project(v))
  244. }
  245. }
  246. }
  247. // Handle javadoc dependencies across projects. Order matters: the linksOffline for
  248. // org.elasticsearch:elasticsearch must be the last one or all the links for the
  249. // other packages (e.g org.elasticsearch.client) will point to server rather than
  250. // their own artifacts.
  251. if (project.plugins.hasPlugin(BuildPlugin) || project.plugins.hasPlugin(PluginBuildPlugin)) {
  252. String artifactsHost = VersionProperties.elasticsearch.endsWith("-SNAPSHOT") ? "https://snapshots.elastic.co" : "https://artifacts.elastic.co"
  253. Closure sortClosure = { a, b -> b.group <=> a.group }
  254. Closure depJavadocClosure = { shadowed, dep ->
  255. if (dep.group == null || false == dep.group.startsWith('org.elasticsearch')) {
  256. return
  257. }
  258. Project upstreamProject = project.ext.dependencyToProject(dep)
  259. if (upstreamProject == null) {
  260. return
  261. }
  262. if (shadowed) {
  263. /*
  264. * Include the source of shadowed upstream projects so we don't
  265. * have to publish their javadoc.
  266. */
  267. project.evaluationDependsOn(upstreamProject.path)
  268. project.javadoc.source += upstreamProject.javadoc.source
  269. /*
  270. * Instead we need the upstream project's javadoc classpath so
  271. * we don't barf on the classes that it references.
  272. */
  273. project.javadoc.classpath += upstreamProject.javadoc.classpath
  274. } else {
  275. // Link to non-shadowed dependant projects
  276. project.javadoc.dependsOn "${upstreamProject.path}:javadoc"
  277. String artifactPath = dep.group.replaceAll('\\.', '/') + '/' + dep.name.replaceAll('\\.', '/') + '/' + dep.version
  278. project.javadoc.options.linksOffline artifactsHost + "/javadoc/" + artifactPath, "${upstreamProject.buildDir}/docs/javadoc/"
  279. }
  280. }
  281. boolean hasShadow = project.plugins.hasPlugin(ShadowPlugin)
  282. project.configurations.compile.dependencies
  283. .findAll()
  284. .toSorted(sortClosure)
  285. .each({ c -> depJavadocClosure(false, c) })
  286. project.configurations.compileOnly.dependencies
  287. .findAll()
  288. .toSorted(sortClosure)
  289. .each({ c -> depJavadocClosure(false, c) })
  290. if (hasShadow) {
  291. project.configurations.bundle.dependencies
  292. .findAll()
  293. .toSorted(sortClosure)
  294. .each({ c -> depJavadocClosure(true, c) })
  295. }
  296. }
  297. }
  298. }
  299. // Ensure similar tasks in dependent projects run first. The projectsEvaluated here is
  300. // important because, while dependencies.all will pickup future dependencies,
  301. // it is not necessarily true that the task exists in both projects at the time
  302. // the dependency is added.
  303. gradle.projectsEvaluated {
  304. allprojects {
  305. if (project.path == ':test:framework') {
  306. // :test:framework:test cannot run before and after :server:test
  307. return
  308. }
  309. if (tasks.findByPath('test') != null && tasks.findByPath('integTest') != null) {
  310. integTest.mustRunAfter test
  311. }
  312. configurations.all { Configuration configuration ->
  313. /*
  314. * The featureAwarePlugin configuration has a dependency on x-pack:plugin:core and x-pack:plugin:core has a dependency on the
  315. * featureAwarePlugin configuration. The below task ordering logic would force :x-pack:plugin:core:test
  316. * :x-pack:test:feature-aware:test to depend on each other circularly. We break that cycle here.
  317. */
  318. if (configuration.name == "featureAwarePlugin") {
  319. return
  320. }
  321. dependencies.all { Dependency dep ->
  322. Project upstreamProject = dependencyToProject(dep)
  323. if (upstreamProject != null) {
  324. if (project.path == upstreamProject.path) {
  325. // TODO: distribution integ tests depend on themselves (!), fix that
  326. return
  327. }
  328. for (String taskName : ['test', 'integTest']) {
  329. Task task = project.tasks.findByName(taskName)
  330. Task upstreamTask = upstreamProject.tasks.findByName(taskName)
  331. if (task != null && upstreamTask != null) {
  332. task.mustRunAfter(upstreamTask)
  333. }
  334. }
  335. }
  336. }
  337. }
  338. }
  339. }
  340. // intellij configuration
  341. allprojects {
  342. apply plugin: 'idea'
  343. if (isIdea) {
  344. project.buildDir = file('build-idea')
  345. }
  346. idea {
  347. module {
  348. inheritOutputDirs = false
  349. outputDir = file('build-idea/classes/main')
  350. testOutputDir = file('build-idea/classes/test')
  351. // also ignore other possible build dirs
  352. excludeDirs += file('build')
  353. excludeDirs += file('build-eclipse')
  354. iml {
  355. // fix so that Gradle idea plugin properly generates support for resource folders
  356. // see also https://issues.gradle.org/browse/GRADLE-2975
  357. withXml {
  358. it.asNode().component.content.sourceFolder.findAll { it.@url == 'file://$MODULE_DIR$/src/main/resources' }.each {
  359. it.attributes().remove('isTestSource')
  360. it.attributes().put('type', 'java-resource')
  361. }
  362. it.asNode().component.content.sourceFolder.findAll { it.@url == 'file://$MODULE_DIR$/src/test/resources' }.each {
  363. it.attributes().remove('isTestSource')
  364. it.attributes().put('type', 'java-test-resource')
  365. }
  366. }
  367. }
  368. }
  369. }
  370. task cleanIdeaBuildDir(type: Delete) {
  371. delete 'build-idea'
  372. }
  373. cleanIdeaBuildDir.setGroup("ide")
  374. cleanIdeaBuildDir.setDescription("Deletes the IDEA build directory.")
  375. tasks.cleanIdea.dependsOn(cleanIdeaBuildDir)
  376. }
  377. idea {
  378. project {
  379. vcs = 'Git'
  380. }
  381. }
  382. // Make sure gradle idea was run before running anything in intellij (including import).
  383. File ideaMarker = new File(projectDir, '.local-idea-is-configured')
  384. tasks.idea.doLast {
  385. ideaMarker.setText('', 'UTF-8')
  386. }
  387. if (System.getProperty('idea.active') != null && ideaMarker.exists() == false) {
  388. throw new GradleException('You must run `./gradlew idea` from the root of elasticsearch before importing into IntelliJ')
  389. }
  390. // eclipse configuration
  391. allprojects {
  392. apply plugin: 'eclipse'
  393. // Name all the non-root projects after their path so that paths get grouped together when imported into eclipse.
  394. if (path != ':') {
  395. eclipse.project.name = path
  396. if (Os.isFamily(Os.FAMILY_WINDOWS)) {
  397. eclipse.project.name = eclipse.project.name.replace(':', '_')
  398. }
  399. }
  400. plugins.withType(JavaBasePlugin) {
  401. File eclipseBuild = project.file('build-eclipse')
  402. eclipse.classpath.defaultOutputDir = eclipseBuild
  403. if (isEclipse) {
  404. // set this so generated dirs will be relative to eclipse build
  405. project.buildDir = eclipseBuild
  406. // Work around https://docs.gradle.org/current/userguide/java_gradle_plugin.html confusing Eclipse by the metadata
  407. // it adds to the classpath
  408. project.file("$buildDir/pluginUnderTestMetadata").mkdirs()
  409. }
  410. eclipse.classpath.file.whenMerged { classpath ->
  411. // give each source folder a unique corresponding output folder
  412. int i = 0;
  413. classpath.entries.findAll { it instanceof SourceFolder }.each { folder ->
  414. i++;
  415. // this is *NOT* a path or a file.
  416. folder.output = "build-eclipse/" + i
  417. }
  418. }
  419. }
  420. File licenseHeaderFile;
  421. String prefix = ':x-pack';
  422. if (Os.isFamily(Os.FAMILY_WINDOWS)) {
  423. prefix = prefix.replace(':', '_')
  424. }
  425. if (eclipse.project.name.startsWith(prefix)) {
  426. licenseHeaderFile = new File(project.rootDir, 'buildSrc/src/main/resources/license-headers/elastic-license-header.txt')
  427. } else {
  428. licenseHeaderFile = new File(project.rootDir, 'buildSrc/src/main/resources/license-headers/oss-license-header.txt')
  429. }
  430. String lineSeparator = Os.isFamily(Os.FAMILY_WINDOWS) ? '\\\\r\\\\n' : '\\\\n'
  431. String licenseHeader = licenseHeaderFile.getText('UTF-8').replace(System.lineSeparator(), lineSeparator)
  432. task copyEclipseSettings(type: Copy) {
  433. // TODO: "package this up" for external builds
  434. from new File(project.rootDir, 'buildSrc/src/main/resources/eclipse.settings')
  435. into '.settings'
  436. filter{ it.replaceAll('@@LICENSE_HEADER_TEXT@@', licenseHeader)}
  437. }
  438. // otherwise .settings is not nuked entirely
  439. task wipeEclipseSettings(type: Delete) {
  440. delete '.settings'
  441. }
  442. tasks.cleanEclipse.dependsOn(wipeEclipseSettings)
  443. // otherwise the eclipse merging is *super confusing*
  444. tasks.eclipse.dependsOn(cleanEclipse, copyEclipseSettings)
  445. // work arround https://github.com/gradle/gradle/issues/6582
  446. tasks.eclipseProject.mustRunAfter tasks.cleanEclipseProject
  447. tasks.matching { it.name == 'eclipseClasspath' }.all {
  448. it.mustRunAfter { tasks.cleanEclipseClasspath }
  449. }
  450. tasks.matching { it.name == 'eclipseJdt' }.all {
  451. it.mustRunAfter { tasks.cleanEclipseJdt }
  452. }
  453. tasks.copyEclipseSettings.mustRunAfter tasks.wipeEclipseSettings
  454. }
  455. allprojects {
  456. /*
  457. * IntelliJ and Eclipse don't know about the shadow plugin so when we're
  458. * in "IntelliJ mode" or "Eclipse mode" switch "bundle" dependencies into
  459. * regular "compile" dependencies. This isn't needed for the project
  460. * itself because the IDE configuration is done by SourceSets but it is
  461. * *is* needed for projects that depends on the project doing the shadowing.
  462. * Without this they won't properly depend on the shadowed project.
  463. */
  464. if (isEclipse || isIdea) {
  465. project.plugins.withType(ShadowPlugin).whenPluginAdded {
  466. project.afterEvaluate {
  467. project.configurations.compile.extendsFrom project.configurations.bundle
  468. }
  469. }
  470. }
  471. }
  472. // we need to add the same --debug-jvm option as
  473. // the real RunTask has, so we can pass it through
  474. class Run extends DefaultTask {
  475. boolean debug = false
  476. @Option(
  477. option = "debug-jvm",
  478. description = "Enable debugging configuration, to allow attaching a debugger to elasticsearch."
  479. )
  480. public void setDebug(boolean enabled) {
  481. project.project(':distribution').run.clusterConfig.debug = enabled
  482. }
  483. }
  484. task run(type: Run) {
  485. dependsOn ':distribution:run'
  486. description = 'Runs elasticsearch in the foreground'
  487. group = 'Verification'
  488. impliesSubProjects = true
  489. }
  490. wrapper {
  491. distributionType = 'ALL'
  492. doLast {
  493. final DistributionLocator locator = new DistributionLocator()
  494. final GradleVersion version = GradleVersion.version(wrapper.gradleVersion)
  495. final URI distributionUri = locator.getDistributionFor(version, wrapper.distributionType.name().toLowerCase(Locale.ENGLISH))
  496. final URI sha256Uri = new URI(distributionUri.toString() + ".sha256")
  497. final String sha256Sum = new String(sha256Uri.toURL().bytes)
  498. wrapper.getPropertiesFile() << "distributionSha256Sum=${sha256Sum}\n"
  499. println "Added checksum to wrapper properties"
  500. // Update build-tools to reflect the Gradle upgrade
  501. // TODO: we can remove this once we have tests to make sure older versions work.
  502. project(':build-tools').file('src/main/resources/minimumGradleVersion').text = gradleVersion
  503. println "Updated minimum Gradle Version"
  504. }
  505. }
  506. gradle.projectsEvaluated {
  507. subprojects {
  508. /*
  509. * Remove assemble/dependenciesInfo on all qa projects because we don't
  510. * need to publish artifacts for them.
  511. */
  512. if (project.name.equals('qa') || project.path.contains(':qa:')) {
  513. Task assemble = project.tasks.findByName('assemble')
  514. if (assemble) {
  515. assemble.enabled = false
  516. }
  517. Task dependenciesInfo = project.tasks.findByName('dependenciesInfo')
  518. if (dependenciesInfo) {
  519. dependenciesInfo.enabled = false
  520. }
  521. }
  522. }
  523. // Having the same group and name for distinct projects causes Gradle to consider them equal when resolving
  524. // dependencies leading to hard to debug failures. Run a check across all project to prevent this from happening.
  525. // see: https://github.com/gradle/gradle/issues/847
  526. Map coordsToProject = [:]
  527. project.allprojects.forEach { p ->
  528. String coords = "${p.group}:${p.name}"
  529. if (false == coordsToProject.putIfAbsent(coords, p)) {
  530. throw new GradleException(
  531. "Detected that two projects: ${p.path} and ${coordsToProject[coords].path} " +
  532. "have the same name and group: ${coords}. " +
  533. "This doesn't currently work correctly in Gradle, see: " +
  534. "https://github.com/gradle/gradle/issues/847"
  535. )
  536. }
  537. }
  538. }
  539. if (System.properties.get("build.compare") != null) {
  540. apply plugin: 'compare-gradle-builds'
  541. compareGradleBuilds {
  542. ext.referenceProject = System.properties.get("build.compare")
  543. doFirst {
  544. if (file(referenceProject).exists() == false) {
  545. throw new GradleException(
  546. "Use git worktree to check out a version to compare against to ../elasticsearch_build_reference"
  547. )
  548. }
  549. }
  550. sourceBuild {
  551. gradleVersion = gradle.getGradleVersion()
  552. projectDir = referenceProject
  553. tasks = ["clean", "assemble"]
  554. arguments = ["-Dbuild.compare_friendly=true"]
  555. }
  556. targetBuild {
  557. tasks = ["clean", "assemble"]
  558. // use -Dorg.gradle.java.home= to alter jdk versions
  559. arguments = ["-Dbuild.compare_friendly=true"]
  560. }
  561. }
  562. }
  563. allprojects {
  564. task resolveAllDependencies {
  565. dependsOn tasks.matching { it.name == "pullFixture"}
  566. doLast {
  567. configurations.findAll { it.isCanBeResolved() }.each { it.resolve() }
  568. }
  569. }
  570. }
  571. allprojects {
  572. task checkPart1
  573. task checkPart2
  574. tasks.matching { it.name == "check" }.all { check ->
  575. if (check.path.startsWith(":x-pack:")) {
  576. checkPart2.dependsOn check
  577. } else {
  578. checkPart1.dependsOn check
  579. }
  580. }
  581. }