Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade gradle wrapper to 4.8 #31525

Merged
merged 29 commits into from
Jun 28, 2018
Merged

Upgrade gradle wrapper to 4.8 #31525

merged 29 commits into from
Jun 28, 2018

Conversation

alpar-t
Copy link
Contributor

@alpar-t alpar-t commented Jun 22, 2018

Switch to gradle 4.8 as discussed in #31230.

Includes:

  • workaround Gradle issues
  • fix the test task replacement that broke in 4.8 and add a sanity check to detect if it happens again
  • add the possibility to compare build artifacts from builds. Useful to check that the changes to the build script did not cause untended changes for the artifacts. This is enabled with a property.

Not strictly Gradle 4.8 but included here as some of the work was done in conjunction with JDK 11:

  • javadoc corrections for problems detected by the newer version of doclint
  • rule in Gradle to always run test before integTest if both are available.

Does not include:

  • remove usage of features deprecated in 4.8

The current does not work with Gradle 4.8 RC1
Relates to elastic#31324. It seems like Gradle has an inconsistent behavior and
the taks is not always replaced.
Closes elastic#31324. The issue has full context in comments.

With this change the `test` task becomes nothing more than an alias for `utest`.
Some of the stand alone tests that had a `test` task now have `integTest`, and a
few of them that used to have `integTest` to run multiple tests now only
have `check`.
This will also help separarate unit/micro tests from integration tests.
Based on information from gradle/gradle#5730 replace the task taking
into account the task providres.
Closes elastic#31324.
@alpar-t alpar-t added the :Delivery/Build Build or test infrastructure label Jun 22, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@alpar-t
Copy link
Contributor Author

alpar-t commented Jun 22, 2018

@nik9000 @rjernst looking forward to your reviews

// https://github.com/elastic/elasticsearch/issues/31324
if (sanityCheckConfigured.getAndSet(true) == false) {
project.rootProject.getGradle().getTaskGraph().whenReady {
def nonConforming = project.getGradle().getTaskGraph().allTasks
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List instead of def? We try to be explicit in types to help those of us used to Java.

newTestTask.dependsOn('testClasses')
// we still have to use replace here despite the remove above because the task container knows about the provider
// by the same name
RandomizedTestingTask newTestTask = tasks.replace('test', RandomizedTestingTask)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need remove at all then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, we don't need to remove with replace.

@alpar-t alpar-t changed the title 31230 gradle48 Upgrade gradle wrapper to 4.8 Jun 26, 2018
Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left two minor things. LGTM otherwise. No need for another round of review I think.

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.*
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't allow * imports in Elasticsearch's code proper because they can make it more difficult to track down where things come from. We probably shouldn't have them here either.

try {
oldTestProvider = tasks.getByNameLater(Test, 'test')
}
catch (UnknownTaskException why) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rename the exception to something more descriptive? why makes me think we don't know why the exception is thrown. Also it'd be lovely if you'd move the catch up to the } line.

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. I left a couple minor nits and questions.

build.gradle Outdated

// make sure integration tests run after unit tests
allprojects {
if (tasks.findByPath('test') != null && tasks.findByPath('integTest') != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put this together in the block around line 319, which also deals with test ordering? What causes this to be a requirement for upgrading to 4.8? Also, separately, I think we should look to make most of these mustRunAfter into shouldRunAfter to allow parallelization.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++ on souldRunAfter. It's not a necessity for Gradle 4.8 but I did find it to be useful when debugging the many problems we had with Gradle 4.8.

private static void configureSanityCheck(Project project) {
// Check the task graph to confirm tasks were indeed replaced
// https://github.com/elastic/elasticsearch/issues/31324
if (sanityCheckConfigured.getAndSet(true) == false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this atomic needed? When is the project ever applied more than once? I think a lot of our code would be broken if it were possible for multiple invocations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plugins is applied once per project, but it's done so on multiple projects.
Since there's a single task graph for all projects, and we must run the check on the task graph rather than the task collection ( as we ween the lather can look right and the former still has the wrong tasks ) we must make sure it's only done once.

@@ -348,7 +348,9 @@ class BuildPlugin implements Plugin<Project> {
// just a self contained test-fixture configuration, likely transitive and hellacious
return
}
configuration.resolutionStrategy.failOnVersionConflict()
configuration.resolutionStrategy {
failOnVersionConflict()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this change out of necessity? It was this way before to match what would be done in java (no closures in java).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more for historic reasons, there was a work-around here with 4.8 that's no longer required in 4.8.1. With Java 8, as there's a functional interface Configuration resolutionStrategy(Action<? super ResolutionStrategy> action); so the closure can be replaced with a lambda. The Gradle API has both closures and functional interfaces in many places.

I'm not entirely convinced about how useful keeping Java like syntax is Groovy will be in aiding conversion after having converted a few files in a different PR. Dynamic Groovy properties are by far harder to deal with than syntax. I would rater adopt a strategy going forward to convert files before doing any edits rather than caring for this syntax, it requires too much attention without it resulting in the end goal.

@@ -625,6 +631,10 @@ class BuildPlugin implements Plugin<Project> {
jarTask.manifest.attributes('Change': shortHash)
}
}
// Force manifest entries that change by nature to a constant to be able to compare builds more effectively
if (System.properties.getProperty("build.compare_friendly", "false") == "true") {
jarTask.manifest.getAttributes().clear()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate more on this comment? I am concerned debug ability of a build that lacks any of the manifest info we inject.

Copy link
Contributor Author

@alpar-t alpar-t Jun 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This property should never be passed directly. It's being used by the build compare plugin.
Unfortunately this useful plugin is still missing a lot of features, like understanding that fields in manifest files will change between builds, so with this property we prevent this to reduce noise in build compare. I'm not happy about what this property does either.
It will backfire, but it does require one to pull the trigger.

@alpar-t alpar-t merged commit 8557bba into elastic:master Jun 28, 2018
@alpar-t alpar-t deleted the 31230_gradle48 branch June 28, 2018 05:13
alpar-t added a commit that referenced this pull request Jun 28, 2018
* Move to Gradle 4.8 RC1

* Use latest version of plugin

The current does not work with Gradle 4.8 RC1

* Switch to Gradle GA

* Add and configure build compare plugin

* add work-around for gradle/gradle#5692

* work around gradle/gradle#5696

* Make use of Gradle build compare with reference project

* Make the manifest more compare friendly

* Clear the manifest in compare friendly mode

* Remove animalsniffer from buildscript classpath

* Fix javadoc errors

* Fix doc issues

* reference Gradle issues in comments

* Conditionally configure build compare

* Fix some more doclint issues

* fix typo in build script

* Add sanity check to make sure the test task was replaced

Relates to #31324. It seems like Gradle has an inconsistent behavior and
the taks is not always replaced.

* Include number of non conforming tasks in the exception.

* No longer replace test task, create implicit instead

Closes #31324. The issue has full context in comments.

With this change the `test` task becomes nothing more than an alias for `utest`.
Some of the stand alone tests that had a `test` task now have `integTest`, and a
few of them that used to have `integTest` to run multiple tests now only
have `check`.
This will also help separarate unit/micro tests from integration tests.

* Revert "No longer replace test task, create implicit instead"

This reverts commit f1ebaf7.

* Fix replacement of the test task

Based on information from gradle/gradle#5730 replace the task taking
into account the task providres.
Closes #31324.

* Only apply build comapare plugin if needed

* Make sure test runs before integTest

* Fix doclint aftter merge

* PR review comments

* Switch to Gradle 4.8.1 and remove workaround

* PR review comments

* Consolidate task ordering
dnhatn added a commit that referenced this pull request Jun 28, 2018
* master:
  Docs: Remove duplicate test setup
  Print output when the name checker IT fails (#31660)
  Fix syntax errors in get-snapshots docs (#31656)
  Docs: Fix description of percentile ranks example example (#31652)
  Add MultiSearchTemplate support to High Level Rest client (#30836)
  Add test for low-level client round-robin behaviour (#31616)
  SQL: Refactor package names of sql-proto and sql-shared-proto projects (#31622)
  Remove deprecation warnings to prepare for Gradle 5 (sourceSets.main.output.classesDirs) (#30389)
  Correct integTest enable logic (#31646)
  Fix missing get-snapshots docs reference #31645
  Do not check for Azure container existence (#31617)
  Merge AwsS3Service and InternalAwsS3Service in a S3Service class (#31580)
  Upgrade gradle wrapper to 4.8 (#31525)
  Only set vm.max_map_count if greater than default (#31512)
  Add Get Snapshots High Level REST API (#31537)
  QA: Merge query-builder-bwc to restart test (#30979)
  Update reindex.asciidoc (#31626)
  Docs: Skip xpack snippet tests if no xpack (#31619)
  mute CreateSnapshotRequestTests
  HLRest: Fix test for explain API
  [TEST] Fix RemoteClusterConnectionTests
  Add Create Snapshot to High-Level Rest Client (#31215)
  Remove legacy MetaDataStateFormat (#31603)
  Add explain API to high-level REST client (#31387)
  Preserve thread context when connecting to remote cluster (#31574)
  Unify headers for full text queries
  Remove redundant 'minimum_should_match'
  JDBC driver prepared statement set* methods  (#31494)
  [TEST] call yaml client close method from test suite (#31591)
dnhatn added a commit that referenced this pull request Jun 28, 2018
* 6.x:
  Docs: Remove duplicate test setup
  Docs: Fix description of percentile ranks example example (#31652)
  Remove deprecation warnings to prepare for Gradle 5 (sourceSets.main.output.classesDirs) (#30389)
  Do not check for Azure container existence (#31617)
  Merge AwsS3Service and InternalAwsS3Service in a S3Service class (#31580)
  Remove item listed in 6.3 notes that's not in 6.3 (#31623)
  remove unused import
  Upgrade gradle wrapper to 4.8 (#31525)
  Only set vm.max_map_count if greater than default (#31512)
  QA: Merge query-builder-bwc to restart test (#30979)
  Docs: Skip xpack snippet tests if no xpack (#31619)
  [TEST] Fix RemoteClusterConnectionTests
  Remove legacy MetaDataStateFormat (#31603)
  [TEST] call yaml client close method from test suite (#31591)
  [TEST] Close additional clients created while running yaml tests (#31575)
  Node selector per client rather than per request (#31471)
  Preserve thread context when connecting to remote cluster (#31574)
  Remove redundant 'minimum_should_match'
  Unify headers for full text queries
  JDBC driver prepared statement set* methods  (#31494)
  add logging breaking changes from 5.3 to 6.0 (#31583)
  Fix a formatting issue in the docvalue_fields documentation. (#31563)
  Improve robustness of geo shape parser for malformed shapes
  QA: Create xpack yaml features (#31403)
@mark-vieira mark-vieira added the Team:Delivery Meta label for Delivery team label Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Delivery/Build Build or test infrastructure Team:Delivery Meta label for Delivery team v6.4.0 v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants