build.gradle 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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 java.nio.file.Files
  20. import org.gradle.util.GradleVersion
  21. plugins {
  22. id 'java-gradle-plugin'
  23. id 'groovy'
  24. }
  25. group = 'org.elasticsearch.gradle'
  26. String minimumGradleVersion = file('src/main/resources/minimumGradleVersion').text.trim()
  27. if (GradleVersion.current() < GradleVersion.version(minimumGradleVersion)) {
  28. throw new GradleException("Gradle ${minimumGradleVersion}+ is required to build elasticsearch")
  29. }
  30. if (JavaVersion.current() < JavaVersion.VERSION_1_8) {
  31. throw new GradleException('Java 1.8 is required to build elasticsearch gradle tools')
  32. }
  33. if (project == rootProject) {
  34. // change the build dir used during build init, so that doing a clean
  35. // won't wipe out the buildscript jar
  36. buildDir = 'build-bootstrap'
  37. }
  38. // Make sure :buildSrc: doesn't generate classes incompatible with RUNTIME_JAVA_HOME
  39. // We can't use BuildPlugin here, so read from file
  40. String minimumRuntimeVersion = file('src/main/resources/minimumRuntimeVersion').text.trim()
  41. targetCompatibility = minimumRuntimeVersion
  42. sourceCompatibility = minimumRuntimeVersion
  43. /*****************************************************************************
  44. * Propagating version.properties to the rest of the build *
  45. *****************************************************************************/
  46. Properties props = new Properties()
  47. props.load(project.file('version.properties').newDataInputStream())
  48. version = props.getProperty('elasticsearch')
  49. boolean snapshot = "true".equals(System.getProperty("build.snapshot", "true"));
  50. if (snapshot) {
  51. // we update the version property to reflect if we are building a snapshot or a release build
  52. // we write this back out below to load it in the Build.java which will be shown in rest main action
  53. // to indicate this being a snapshot build or a release build.
  54. version += "-SNAPSHOT"
  55. props.put("elasticsearch", version);
  56. }
  57. File tempPropertiesFile = new File(project.buildDir, "version.properties")
  58. task writeVersionProperties {
  59. inputs.properties(props)
  60. outputs.file(tempPropertiesFile)
  61. doLast {
  62. OutputStream stream = Files.newOutputStream(tempPropertiesFile.toPath());
  63. try {
  64. props.store(stream, "UTF-8");
  65. } finally {
  66. stream.close();
  67. }
  68. }
  69. }
  70. processResources {
  71. dependsOn writeVersionProperties
  72. from tempPropertiesFile
  73. }
  74. /*****************************************************************************
  75. * Dependencies used by the entire build *
  76. *****************************************************************************/
  77. repositories {
  78. jcenter()
  79. }
  80. dependencies {
  81. compile localGroovy()
  82. compile "com.carrotsearch.randomizedtesting:junit4-ant:${props.getProperty('randomizedrunner')}"
  83. compile "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${props.getProperty('randomizedrunner')}"
  84. compile("junit:junit:${props.getProperty('junit')}") {
  85. transitive = false
  86. }
  87. compile 'com.netflix.nebula:gradle-extra-configurations-plugin:3.0.3'
  88. compile 'com.netflix.nebula:nebula-publishing-plugin:4.4.4'
  89. compile 'com.netflix.nebula:gradle-info-plugin:3.0.3'
  90. compile 'org.eclipse.jgit:org.eclipse.jgit:3.2.0.201312181205-r'
  91. compile 'com.perforce:p4java:2012.3.551082' // THIS IS SUPPOSED TO BE OPTIONAL IN THE FUTURE....
  92. compile 'org.apache.rat:apache-rat:0.11'
  93. compile "org.elasticsearch:jna:4.5.1"
  94. compile 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
  95. testCompile "junit:junit:${props.getProperty('junit')}"
  96. }
  97. // Gradle 2.14+ removed ProgressLogger(-Factory) classes from the public APIs
  98. // Use logging dependency instead
  99. // Gradle 4.3.1 stopped releasing the logging jars to jcenter, just use the last available one
  100. GradleVersion logVersion = GradleVersion.current() > GradleVersion.version('4.3') ? GradleVersion.version('4.3') : GradleVersion.current()
  101. dependencies {
  102. compileOnly "org.gradle:gradle-logging:${logVersion.getVersion()}"
  103. }
  104. /*****************************************************************************
  105. * Bootstrap repositories *
  106. *****************************************************************************/
  107. // this will only happen when buildSrc is built on its own during build init
  108. if (project == rootProject) {
  109. repositories {
  110. if (System.getProperty("repos.mavenLocal") != null) {
  111. mavenLocal()
  112. }
  113. mavenCentral()
  114. }
  115. test {
  116. include "**/*Tests.class"
  117. exclude "**/*IT.class"
  118. }
  119. }
  120. /*****************************************************************************
  121. * Normal project checks *
  122. *****************************************************************************/
  123. // this happens when included as a normal project in the build, which we do
  124. // to enforce precommit checks like forbidden apis, as well as setup publishing
  125. if (project != rootProject) {
  126. apply plugin: 'elasticsearch.build'
  127. apply plugin: 'nebula.maven-base-publish'
  128. apply plugin: 'nebula.maven-scm'
  129. // groovydoc succeeds, but has some weird internal exception...
  130. groovydoc.enabled = false
  131. // build-tools is not ready for primetime with these...
  132. dependencyLicenses.enabled = false
  133. dependenciesInfo.enabled = false
  134. forbiddenApisMain.enabled = false
  135. forbiddenApisTest.enabled = false
  136. jarHell.enabled = false
  137. thirdPartyAudit.enabled = false
  138. // tests can't be run with randomized test runner
  139. // it's fine as we run them as part of :buildSrc
  140. test.enabled = false
  141. task integTest(type: Test) {
  142. // integration test requires the local testing repo for example plugin builds
  143. dependsOn project.rootProject.allprojects.collect {
  144. it.tasks.matching { it.name == 'publishNebulaPublicationToLocalTestRepository'}
  145. }
  146. exclude "**/*Tests.class"
  147. testClassesDirs = sourceSets.test.output.classesDirs
  148. classpath = sourceSets.test.runtimeClasspath
  149. inputs.dir(file("src/testKit"))
  150. // tell BuildExamplePluginsIT where to find the example plugins
  151. systemProperty (
  152. 'test.build-tools.plugin.examples',
  153. files(
  154. project(':example-plugins').subprojects.collect { it.projectDir }
  155. ).asPath,
  156. )
  157. systemProperty 'test.local-test-repo-path', "${rootProject.buildDir}/local-test-repo"
  158. systemProperty 'test.lucene-snapshot-revision', (versions.lucene =~ /\w+-snapshot-([a-z0-9]+)/)[0][1]
  159. }
  160. check.dependsOn(integTest)
  161. // TODO: re-enable once randomizedtesting gradle code is published and removed from here
  162. licenseHeaders.enabled = false
  163. forbiddenPatterns {
  164. exclude '**/*.wav'
  165. // the file that actually defines nocommit
  166. exclude '**/ForbiddenPatternsTask.groovy'
  167. }
  168. namingConventions {
  169. testClass = 'org.elasticsearch.gradle.test.GradleUnitTestCase'
  170. integTestClass = 'org.elasticsearch.gradle.test.GradleIntegrationTestCase'
  171. }
  172. /*
  173. * We alread configure publication and we don't need or want this one that
  174. * comes from the java-gradle-plugin.
  175. */
  176. afterEvaluate {
  177. generatePomFileForPluginMavenPublication.enabled = false
  178. }
  179. }