build.gradle 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  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 org.apache.tools.ant.taskdefs.condition.Os
  20. import org.apache.tools.ant.filters.ReplaceTokens
  21. import org.elasticsearch.gradle.BuildPlugin
  22. import org.elasticsearch.gradle.LoggedExec
  23. import org.elasticsearch.gradle.Version
  24. import org.elasticsearch.gradle.VersionCollection
  25. import org.elasticsearch.gradle.VersionProperties
  26. import org.gradle.plugins.ide.eclipse.model.SourceFolder
  27. import org.gradle.api.tasks.wrapper.Wrapper
  28. import org.gradle.api.tasks.wrapper.Wrapper.DistributionType
  29. import org.gradle.util.GradleVersion
  30. import org.gradle.util.DistributionLocator
  31. import java.nio.file.Files
  32. import java.nio.file.Path
  33. import java.security.MessageDigest
  34. // common maven publishing configuration
  35. subprojects {
  36. group = 'org.elasticsearch'
  37. version = VersionProperties.elasticsearch.toString()
  38. description = "Elasticsearch subproject ${project.path}"
  39. }
  40. subprojects {
  41. project.ext.licenseName = 'The Apache Software License, Version 2.0'
  42. project.ext.licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
  43. // we only use maven publish to add tasks for pom generation
  44. plugins.withType(MavenPublishPlugin).whenPluginAdded {
  45. publishing {
  46. publications {
  47. // add license information to generated poms
  48. all {
  49. pom.withXml { XmlProvider xml ->
  50. Node node = xml.asNode()
  51. node.appendNode('inceptionYear', '2009')
  52. Node license = node.appendNode('licenses').appendNode('license')
  53. license.appendNode('name', project.licenseName)
  54. license.appendNode('url', project.licenseUrl)
  55. license.appendNode('distribution', 'repo')
  56. Node developer = node.appendNode('developers').appendNode('developer')
  57. developer.appendNode('name', 'Elastic')
  58. developer.appendNode('url', 'http://www.elastic.co')
  59. }
  60. }
  61. }
  62. }
  63. }
  64. plugins.withType(BuildPlugin).whenPluginAdded {
  65. project.licenseFile = project.rootProject.file('licenses/APACHE-LICENSE-2.0.txt')
  66. project.noticeFile = project.rootProject.file('NOTICE.txt')
  67. }
  68. }
  69. /* Introspect all versions of ES that may be tested against for backwards
  70. * compatibility. It is *super* important that this logic is the same as the
  71. * logic in VersionUtils.java, throwing out alphas because they don't have any
  72. * backwards compatibility guarantees and only keeping the latest beta or rc
  73. * in a branch if there are only betas and rcs in the branch so we have
  74. * *something* to test against. */
  75. VersionCollection versions = new VersionCollection(file('server/src/main/java/org/elasticsearch/Version.java').readLines('UTF-8'))
  76. if (versions.currentVersion != VersionProperties.elasticsearch) {
  77. throw new GradleException("The last version in Versions.java [${versions.currentVersion}] does not match " +
  78. "VersionProperties.elasticsearch [${VersionProperties.elasticsearch}]")
  79. }
  80. // build metadata from previous build, contains eg hashes for bwc builds
  81. String buildMetadataValue = System.getenv('BUILD_METADATA')
  82. if (buildMetadataValue == null) {
  83. buildMetadataValue = ''
  84. }
  85. Map<String, String> buildMetadataMap = buildMetadataValue.tokenize(';').collectEntries {
  86. def (String key, String value) = it.split('=')
  87. return [key, value]
  88. }
  89. // injecting groovy property variables into all projects
  90. allprojects {
  91. project.ext {
  92. // for ide hacks...
  93. isEclipse = System.getProperty("eclipse.launcher") != null || gradle.startParameter.taskNames.contains('eclipse') || gradle.startParameter.taskNames.contains('cleanEclipse')
  94. isIdea = System.getProperty("idea.active") != null || gradle.startParameter.taskNames.contains('idea') || gradle.startParameter.taskNames.contains('cleanIdea')
  95. // for BWC testing
  96. bwcVersions = versions
  97. buildMetadata = buildMetadataMap
  98. }
  99. }
  100. task verifyVersions {
  101. doLast {
  102. if (gradle.startParameter.isOffline()) {
  103. throw new GradleException("Must run in online mode to verify versions")
  104. }
  105. // Read the list from maven central
  106. Node xml
  107. new URL('https://repo1.maven.org/maven2/org/elasticsearch/elasticsearch/maven-metadata.xml').openStream().withStream { s ->
  108. xml = new XmlParser().parse(s)
  109. }
  110. Set<Version> knownVersions = new TreeSet<>(xml.versioning.versions.version.collect { it.text() }.findAll { it ==~ /\d\.\d\.\d/ }.collect { Version.fromString(it) })
  111. // Limit the known versions to those that should be index compatible, and are not future versions
  112. knownVersions = knownVersions.findAll { it.major >= bwcVersions.currentVersion.major - 1 && it.before(VersionProperties.elasticsearch) }
  113. /* Limit the listed versions to those that have been marked as released.
  114. * Versions not marked as released don't get the same testing and we want
  115. * to make sure that we flip all unreleased versions to released as soon
  116. * as possible after release. */
  117. Set<Version> actualVersions = new TreeSet<>(bwcVersions.indexCompatible.findAll { false == it.snapshot })
  118. // Finally, compare!
  119. if (knownVersions.equals(actualVersions) == false) {
  120. throw new GradleException("out-of-date released versions\nActual :" + actualVersions + "\nExpected:" + knownVersions +
  121. "\nUpdate Version.java. Note that Version.CURRENT doesn't count because it is not released.")
  122. }
  123. }
  124. }
  125. /*
  126. * When adding backcompat behavior that spans major versions, temporarily
  127. * disabling the backcompat tests is necessary. This flag controls
  128. * the enabled state of every bwc task. It should be set back to true
  129. * after the backport of the backcompat code is complete.
  130. */
  131. final boolean bwc_tests_enabled = true
  132. final String bwc_tests_disabled_issue = "" /* place a PR link here when commiting bwc changes */
  133. if (bwc_tests_enabled == false) {
  134. if (bwc_tests_disabled_issue.isEmpty()) {
  135. throw new GradleException("bwc_tests_disabled_issue must be set when bwc_tests_enabled == false")
  136. }
  137. println "========================= WARNING ========================="
  138. println " Backwards compatibility tests are disabled!"
  139. println "See ${bwc_tests_disabled_issue}"
  140. println "==========================================================="
  141. }
  142. subprojects {
  143. ext.bwc_tests_enabled = bwc_tests_enabled
  144. }
  145. task verifyBwcTestsEnabled {
  146. doLast {
  147. if (bwc_tests_enabled == false) {
  148. throw new GradleException('Bwc tests are disabled. They must be re-enabled after completing backcompat behavior backporting.')
  149. }
  150. }
  151. }
  152. task branchConsistency {
  153. description 'Ensures this branch is internally consistent. For example, that versions constants match released versions.'
  154. group 'Verification'
  155. dependsOn verifyVersions, verifyBwcTestsEnabled
  156. }
  157. subprojects {
  158. // ignore missing javadocs
  159. tasks.withType(Javadoc) { Javadoc javadoc ->
  160. // the -quiet here is because of a bug in gradle, in that adding a string option
  161. // by itself is not added to the options. By adding quiet, both this option and
  162. // the "value" -quiet is added, separated by a space. This is ok since the javadoc
  163. // command already adds -quiet, so we are just duplicating it
  164. // see https://discuss.gradle.org/t/add-custom-javadoc-option-that-does-not-take-an-argument/5959
  165. javadoc.options.encoding='UTF8'
  166. javadoc.options.addStringOption('Xdoclint:all,-missing', '-quiet')
  167. }
  168. /* Sets up the dependencies that we build as part of this project but
  169. register as thought they were external to resolve internally. We register
  170. them as external dependencies so the build plugin that we use can be used
  171. to build elasticsearch plugins outside of the elasticsearch source tree. */
  172. ext.projectSubstitutions = [
  173. "org.elasticsearch.gradle:build-tools:${version}": ':build-tools',
  174. "org.elasticsearch:rest-api-spec:${version}": ':rest-api-spec',
  175. "org.elasticsearch:elasticsearch:${version}": ':server',
  176. "org.elasticsearch:elasticsearch-cli:${version}": ':server:cli',
  177. "org.elasticsearch:elasticsearch-core:${version}": ':libs:elasticsearch-core',
  178. "org.elasticsearch:elasticsearch-nio:${version}": ':libs:elasticsearch-nio',
  179. "org.elasticsearch:elasticsearch-x-content:${version}": ':libs:x-content',
  180. "org.elasticsearch:elasticsearch-secure-sm:${version}": ':libs:secure-sm',
  181. "org.elasticsearch.client:elasticsearch-rest-client:${version}": ':client:rest',
  182. "org.elasticsearch.client:elasticsearch-rest-client-sniffer:${version}": ':client:sniffer',
  183. "org.elasticsearch.client:elasticsearch-rest-high-level-client:${version}": ':client:rest-high-level',
  184. "org.elasticsearch.client:test:${version}": ':client:test',
  185. "org.elasticsearch.client:transport:${version}": ':client:transport',
  186. "org.elasticsearch.test:framework:${version}": ':test:framework',
  187. "org.elasticsearch.distribution.integ-test-zip:elasticsearch:${version}": ':distribution:archives:integ-test-zip',
  188. "org.elasticsearch.distribution.zip:elasticsearch:${version}": ':distribution:archives:zip',
  189. "org.elasticsearch.distribution.zip:elasticsearch-oss:${version}": ':distribution:archives:oss-zip',
  190. "org.elasticsearch.distribution.tar:elasticsearch:${version}": ':distribution:archives:tar',
  191. "org.elasticsearch.distribution.tar:elasticsearch-oss:${version}": ':distribution:archives:oss-tar',
  192. "org.elasticsearch.distribution.rpm:elasticsearch:${version}": ':distribution:packages:rpm',
  193. "org.elasticsearch.distribution.rpm:elasticsearch-oss:${version}": ':distribution:packages:oss-rpm',
  194. "org.elasticsearch.distribution.deb:elasticsearch:${version}": ':distribution:packages:deb',
  195. "org.elasticsearch.distribution.deb:elasticsearch-oss:${version}": ':distribution:packages:oss-deb',
  196. "org.elasticsearch.test:logger-usage:${version}": ':test:logger-usage',
  197. // for transport client
  198. "org.elasticsearch.plugin:transport-netty4-client:${version}": ':modules:transport-netty4',
  199. "org.elasticsearch.plugin:reindex-client:${version}": ':modules:reindex',
  200. "org.elasticsearch.plugin:lang-mustache-client:${version}": ':modules:lang-mustache',
  201. "org.elasticsearch.plugin:parent-join-client:${version}": ':modules:parent-join',
  202. "org.elasticsearch.plugin:aggs-matrix-stats-client:${version}": ':modules:aggs-matrix-stats',
  203. "org.elasticsearch.plugin:percolator-client:${version}": ':modules:percolator',
  204. "org.elasticsearch.plugin:rank-eval-client:${version}": ':modules:rank-eval',
  205. ]
  206. bwcVersions.snapshotProjectNames.each { snapshotName ->
  207. Version snapshot = bwcVersions.getSnapshotForProject(snapshotName)
  208. if (snapshot != null ) {
  209. String snapshotProject = ":distribution:bwc:${snapshotName}"
  210. project(snapshotProject).ext.bwcVersion = snapshot
  211. ext.projectSubstitutions["org.elasticsearch.distribution.deb:elasticsearch:${snapshot}"] = snapshotProject
  212. ext.projectSubstitutions["org.elasticsearch.distribution.rpm:elasticsearch:${snapshot}"] = snapshotProject
  213. ext.projectSubstitutions["org.elasticsearch.distribution.zip:elasticsearch:${snapshot}"] = snapshotProject
  214. if (snapshot.onOrAfter('6.3.0')) {
  215. ext.projectSubstitutions["org.elasticsearch.distribution.deb:elasticsearch-oss:${snapshot}"] = snapshotProject
  216. ext.projectSubstitutions["org.elasticsearch.distribution.rpm:elasticsearch-oss:${snapshot}"] = snapshotProject
  217. ext.projectSubstitutions["org.elasticsearch.distribution.zip:elasticsearch-oss:${snapshot}"] = snapshotProject
  218. }
  219. }
  220. }
  221. /*
  222. * Gradle only resolve project substitutions during dependency resolution but
  223. * we sometimes want to do the resolution at other times. This creates a
  224. * convenient method we can call to do it.
  225. */
  226. ext.dependencyToProject = { Dependency dep ->
  227. if (dep instanceof ProjectDependency) {
  228. return dep.dependencyProject
  229. } else {
  230. String substitution = projectSubstitutions.get("${dep.group}:${dep.name}:${dep.version}")
  231. if (substitution != null) {
  232. return findProject(substitution)
  233. }
  234. return null
  235. }
  236. }
  237. project.afterEvaluate {
  238. configurations.all {
  239. resolutionStrategy.dependencySubstitution { DependencySubstitutions subs ->
  240. projectSubstitutions.each { k,v ->
  241. subs.substitute(subs.module(k)).with(subs.project(v))
  242. }
  243. }
  244. }
  245. // Handle javadoc dependencies across projects. Order matters: the linksOffline for
  246. // org.elasticsearch:elasticsearch must be the last one or all the links for the
  247. // other packages (e.g org.elasticsearch.client) will point to server rather than
  248. // their own artifacts.
  249. if (project.plugins.hasPlugin(BuildPlugin)) {
  250. String artifactsHost = VersionProperties.elasticsearch.isSnapshot() ? "https://snapshots.elastic.co" : "https://artifacts.elastic.co"
  251. Closure sortClosure = { a, b -> b.group <=> a.group }
  252. Closure depJavadocClosure = { dep ->
  253. if (dep.group != null && dep.group.startsWith('org.elasticsearch')) {
  254. Project upstreamProject = dependencyToProject(dep)
  255. if (upstreamProject != null) {
  256. project.javadoc.dependsOn "${upstreamProject.path}:javadoc"
  257. String artifactPath = dep.group.replaceAll('\\.', '/') + '/' + dep.name.replaceAll('\\.', '/') + '/' + dep.version
  258. project.javadoc.options.linksOffline artifactsHost + "/javadoc/" + artifactPath, "${upstreamProject.buildDir}/docs/javadoc/"
  259. }
  260. }
  261. }
  262. project.configurations.compile.dependencies.findAll().toSorted(sortClosure).each(depJavadocClosure)
  263. project.configurations.compileOnly.dependencies.findAll().toSorted(sortClosure).each(depJavadocClosure)
  264. }
  265. }
  266. }
  267. // Ensure similar tasks in dependent projects run first. The projectsEvaluated here is
  268. // important because, while dependencies.all will pickup future dependencies,
  269. // it is not necessarily true that the task exists in both projects at the time
  270. // the dependency is added.
  271. gradle.projectsEvaluated {
  272. allprojects {
  273. if (project.path == ':test:framework') {
  274. // :test:framework:test cannot run before and after :server:test
  275. return
  276. }
  277. configurations.all {
  278. dependencies.all { Dependency dep ->
  279. Project upstreamProject = dependencyToProject(dep)
  280. if (upstreamProject != null) {
  281. if (project.path == upstreamProject.path) {
  282. // TODO: distribution integ tests depend on themselves (!), fix that
  283. return
  284. }
  285. for (String taskName : ['test', 'integTest']) {
  286. Task task = project.tasks.findByName(taskName)
  287. Task upstreamTask = upstreamProject.tasks.findByName(taskName)
  288. if (task != null && upstreamTask != null) {
  289. task.mustRunAfter(upstreamTask)
  290. }
  291. }
  292. }
  293. }
  294. }
  295. }
  296. }
  297. // intellij configuration
  298. allprojects {
  299. apply plugin: 'idea'
  300. if (isIdea) {
  301. project.buildDir = file('build-idea')
  302. }
  303. idea {
  304. module {
  305. inheritOutputDirs = false
  306. outputDir = file('build-idea/classes/main')
  307. testOutputDir = file('build-idea/classes/test')
  308. // also ignore other possible build dirs
  309. excludeDirs += file('build')
  310. excludeDirs += file('build-eclipse')
  311. iml {
  312. // fix so that Gradle idea plugin properly generates support for resource folders
  313. // see also https://issues.gradle.org/browse/GRADLE-2975
  314. withXml {
  315. it.asNode().component.content.sourceFolder.findAll { it.@url == 'file://$MODULE_DIR$/src/main/resources' }.each {
  316. it.attributes().remove('isTestSource')
  317. it.attributes().put('type', 'java-resource')
  318. }
  319. it.asNode().component.content.sourceFolder.findAll { it.@url == 'file://$MODULE_DIR$/src/test/resources' }.each {
  320. it.attributes().remove('isTestSource')
  321. it.attributes().put('type', 'java-test-resource')
  322. }
  323. }
  324. }
  325. }
  326. }
  327. task cleanIdeaBuildDir(type: Delete) {
  328. delete 'build-idea'
  329. }
  330. cleanIdeaBuildDir.setGroup("ide")
  331. cleanIdeaBuildDir.setDescription("Deletes the IDEA build directory.")
  332. tasks.cleanIdea.dependsOn(cleanIdeaBuildDir)
  333. }
  334. idea {
  335. project {
  336. vcs = 'Git'
  337. }
  338. }
  339. // Make sure gradle idea was run before running anything in intellij (including import).
  340. File ideaMarker = new File(projectDir, '.local-idea-is-configured')
  341. tasks.idea.doLast {
  342. ideaMarker.setText('', 'UTF-8')
  343. }
  344. if (System.getProperty('idea.active') != null && ideaMarker.exists() == false) {
  345. throw new GradleException('You must run gradle idea from the root of elasticsearch before importing into IntelliJ')
  346. }
  347. // eclipse configuration
  348. allprojects {
  349. apply plugin: 'eclipse'
  350. // Name all the non-root projects after their path so that paths get grouped together when imported into eclipse.
  351. if (path != ':') {
  352. eclipse.project.name = path
  353. if (Os.isFamily(Os.FAMILY_WINDOWS)) {
  354. eclipse.project.name = eclipse.project.name.replace(':', '_')
  355. }
  356. }
  357. plugins.withType(JavaBasePlugin) {
  358. File eclipseBuild = project.file('build-eclipse')
  359. eclipse.classpath.defaultOutputDir = eclipseBuild
  360. if (isEclipse) {
  361. // set this so generated dirs will be relative to eclipse build
  362. project.buildDir = eclipseBuild
  363. }
  364. eclipse.classpath.file.whenMerged { classpath ->
  365. // give each source folder a unique corresponding output folder
  366. int i = 0;
  367. classpath.entries.findAll { it instanceof SourceFolder }.each { folder ->
  368. i++;
  369. // this is *NOT* a path or a file.
  370. folder.output = "build-eclipse/" + i
  371. }
  372. }
  373. }
  374. File licenseHeaderFile;
  375. if (eclipse.project.name.startsWith(':x-pack')) {
  376. licenseHeaderFile = new File(project.rootDir, 'buildSrc/src/main/resources/license-headers/elastic-license-header.txt')
  377. } else {
  378. licenseHeaderFile = new File(project.rootDir, 'buildSrc/src/main/resources/license-headers/oss-license-header.txt')
  379. }
  380. String licenseHeader = licenseHeaderFile.getText('UTF-8').replace('\n', '\\\\n')
  381. task copyEclipseSettings(type: Copy) {
  382. // TODO: "package this up" for external builds
  383. from new File(project.rootDir, 'buildSrc/src/main/resources/eclipse.settings')
  384. into '.settings'
  385. filter{ it.replaceAll('@@LICENSE_HEADER_TEXT@@', licenseHeader)}
  386. }
  387. // otherwise .settings is not nuked entirely
  388. task wipeEclipseSettings(type: Delete) {
  389. delete '.settings'
  390. }
  391. tasks.cleanEclipse.dependsOn(wipeEclipseSettings)
  392. // otherwise the eclipse merging is *super confusing*
  393. tasks.eclipse.dependsOn(cleanEclipse, copyEclipseSettings)
  394. }
  395. // we need to add the same --debug-jvm option as
  396. // the real RunTask has, so we can pass it through
  397. class Run extends DefaultTask {
  398. boolean debug = false
  399. @org.gradle.api.internal.tasks.options.Option(
  400. option = "debug-jvm",
  401. description = "Enable debugging configuration, to allow attaching a debugger to elasticsearch."
  402. )
  403. public void setDebug(boolean enabled) {
  404. project.project(':distribution').run.clusterConfig.debug = enabled
  405. }
  406. }
  407. task run(type: Run) {
  408. dependsOn ':distribution:run'
  409. description = 'Runs elasticsearch in the foreground'
  410. group = 'Verification'
  411. impliesSubProjects = true
  412. }
  413. task wrapper(type: Wrapper)
  414. gradle.projectsEvaluated {
  415. allprojects {
  416. tasks.withType(Wrapper) { Wrapper wrapper ->
  417. wrapper.distributionType = DistributionType.ALL
  418. wrapper.doLast {
  419. final DistributionLocator locator = new DistributionLocator()
  420. final GradleVersion version = GradleVersion.version(wrapper.gradleVersion)
  421. final URI distributionUri = locator.getDistributionFor(version, wrapper.distributionType.name().toLowerCase(Locale.ENGLISH))
  422. final URI sha256Uri = new URI(distributionUri.toString() + ".sha256")
  423. final String sha256Sum = new String(sha256Uri.toURL().bytes)
  424. wrapper.getPropertiesFile() << "distributionSha256Sum=${sha256Sum}\n"
  425. }
  426. }
  427. }
  428. }
  429. static void assertLinesInFile(final Path path, final List<String> expectedLines) {
  430. final List<String> actualLines = Files.readAllLines(path)
  431. int line = 0
  432. for (final String expectedLine : expectedLines) {
  433. final String actualLine = actualLines.get(line)
  434. if (expectedLine != actualLine) {
  435. throw new GradleException("expected line [${line + 1}] in [${path}] to be [${expectedLine}] but was [${actualLine}]")
  436. }
  437. line++
  438. }
  439. }
  440. /*
  441. * Check that all generated JARs have our NOTICE.txt and an appropriate
  442. * LICENSE.txt in them. We configurate this in gradle but we'd like to
  443. * be extra paranoid.
  444. */
  445. subprojects { project ->
  446. project.tasks.withType(Jar).whenTaskAdded { jarTask ->
  447. final Task extract = project.task("extract${jarTask.name.capitalize()}", type: LoggedExec) {
  448. dependsOn jarTask
  449. ext.destination = project.buildDir.toPath().resolve("jar-extracted/${jarTask.name}")
  450. commandLine "${->new File(rootProject.compilerJavaHome, 'bin/jar')}",
  451. 'xf', "${-> jarTask.outputs.files.singleFile}", 'META-INF/LICENSE.txt', 'META-INF/NOTICE.txt'
  452. workingDir destination
  453. doFirst {
  454. project.delete(destination)
  455. Files.createDirectories(destination)
  456. }
  457. }
  458. final Task checkNotice = project.task("verify${jarTask.name.capitalize()}Notice") {
  459. dependsOn extract
  460. doLast {
  461. final List<String> noticeLines = Files.readAllLines(project.noticeFile.toPath())
  462. final Path noticePath = extract.destination.resolve('META-INF/NOTICE.txt')
  463. assertLinesInFile(noticePath, noticeLines)
  464. }
  465. }
  466. project.check.dependsOn checkNotice
  467. final Task checkLicense = project.task("verify${jarTask.name.capitalize()}License") {
  468. dependsOn extract
  469. doLast {
  470. final List<String> licenseLines = Files.readAllLines(project.licenseFile.toPath())
  471. final Path licensePath = extract.destination.resolve('META-INF/LICENSE.txt')
  472. assertLinesInFile(licensePath, licenseLines)
  473. }
  474. }
  475. project.check.dependsOn checkLicense
  476. }
  477. }
  478. /* Remove assemble on all qa projects because we don't need to publish
  479. * artifacts for them. */
  480. gradle.projectsEvaluated {
  481. subprojects {
  482. if (project.path.startsWith(':qa')) {
  483. Task assemble = project.tasks.findByName('assemble')
  484. if (assemble) {
  485. project.tasks.remove(assemble)
  486. project.build.dependsOn.remove('assemble')
  487. }
  488. }
  489. }
  490. }