-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Build: Fail if any libs depend on non-core libs #29336
Conversation
Adds a `precommit` to every subprojects of `:libs` that fails the build if there are any `:libs` dependencies. I imagine it'd be possible to fail the build on startup if the dependencies are unacceptable rather than use a precommit task but the precommit task reports the error nicely and is easy to skip if for some reason we want to temporarily skip it. So it felt like the right way to go. Since we now have three places where we resolve project substitutions I've added `dependencyToProject` to `project.ext` in all projects. It resolves both `project` style dependencies and "external" style (like "org.elasticsearch:elasticsearch-core:${version}") dependencies to `Project`s using the `projectSubstitutions`. I use this new function all three places where resovle project substitutions. Finally this pulls `apply plugin: 'elasticsearch.build'` out of `libs/*/build.gradle` and into a subprojects clause in `libs/build.gradle`. I do this entirely so that I can call `tasks.precommit.dependsOn checkDependencies` without waiting for the subprojects to be evaluated or worrying about whether or not they have `precommit` set up in a normal way.
Pinging @elastic/es-core-infra |
I don't think we should do this as a task. This should fail during configuration. We already do similar traversal inside BuildPlugin.configureConfigurations, where we disable transitive dependencies (and always force version conflict failure). I also think this is going to be a little more complicated as we need "groups" of libs that can have dependencies on each other (eg painless is going to have painless-compiler and painless-whitelist jars). |
I think we can wait to cross that bridge when we get there. |
I'm in the middle of splitting the painless jars out right now. |
That is, by my estimation, at least two if not three weeks away. Let us make the "group" change a follow-up to this PR, we can progress when the need is clearer. |
That's fine, but my concern about the way this is implemented still stands. Doing it via a task is not right; it needs to be checked during configuration. |
I have no objections to that, my comment was only about adding the "group" requirement on top of this specific PR. |
If I think "there are two ways to do this and either are just fine" and I basically flip a coin @rjernst almost always has good arguments against the result of my coin flip. Well, more again the "either are just fine" part of my reasoning, but still. I'll change it to fail on startup. |
I've switched this to run during configuration. |
@rjernst, would you like to take another look? I've switched this to run during configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks much better @nik9000, thanks! I left a few comments.
libs/build.gradle
Outdated
|
||
/* | ||
* Subprojects may depend on the "core" lib but may not depend on any | ||
* other Elasticsearch code. This keeps are dependencies simpler to think |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
other Elasticsearch code
-> other lib
Also, I would reword the second sentence to "This keeps the dependency graph simple"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++
libs/build.gradle
Outdated
configurations.all { Configuration conf -> | ||
dependencies.all { Dependency dep -> | ||
if (project.name.equals('elasticsearch-nio')) { | ||
System.err.println("ccc $conf.name $dep") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like leftover debugging?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll shoot it.
libs/build.gradle
Outdated
throw new InvalidUserDataException("projects in :libs " | ||
+ "may not depend on other projects libs except " | ||
+ ":libs:elasticsearch-core but " | ||
+ "$project.path depends on $depProject.path") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need brackets around these derefs? ${project.path} depends on ${depProject.path}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It isn't required but if you like it better I'm happy to do it that way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is clearer that way.
Fails the build if any subprojects of `:libs` have dependencies in `:libs` except for `:libs:elasticsearch-core`. Since we now have three places where we resolve project substitutions I've added `dependencyToProject` to `project.ext` in all projects. It resolves both `project` style dependencies and "external" style (like "org.elasticsearch:elasticsearch-core:${version}") dependencies to `Project`s using the `projectSubstitutions`. I use this new function all three places where resovle project substitutions. Finally this pulls `apply plugin: 'elasticsearch.build'` out of `libs/*/build.gradle` and into a subprojects clause in `libs/build.gradle`. I do this entirely so that I can call `tasks.precommit.dependsOn checkDependencies` without waiting for the subprojects to be evaluated or worrying about whether or not they have `precommit` set up in a normal way.
* master: Remove PipelineExecutionService#executeIndexRequest (elastic#29537) Fix overflow error in parsing of long geohashes (elastic#29418) Remove unused index.ttl.disable_purge setting (elastic#29527) FullClusterRestartIT.testRecovery should wait for all initializing shards Build: Fail if any libs depend on non-core libs (elastic#29336)
* master: (96 commits) TEST: Mute testEnsureWeReconnect Mute full cluster restart test recovery test REST high-level client: add support for Indices Update Settings API [take 2] (elastic#29327) Plugins: Fix native controller confirmation for non-meta plugin (elastic#29434) Remove PipelineExecutionService#executeIndexRequest (elastic#29537) Fix overflow error in parsing of long geohashes (elastic#29418) Remove unused index.ttl.disable_purge setting (elastic#29527) FullClusterRestartIT.testRecovery should wait for all initializing shards Build: Fail if any libs depend on non-core libs (elastic#29336) [TEST] REST client request without leading '/' (elastic#29471) Using ObjectParser in UpdateRequest (elastic#29293) Prevent accidental changes of default values (elastic#29528) [Docs] Add definitions to glossary (elastic#29127) Avoid self-deadlock in the translog (elastic#29520) Minor cleanup in NodeInfo.groovy Lazy configure build tasks that require older JDKs (elastic#29519) Simplify snapshot check in root build file Make NodeInfo#nodeVersion strongly-typed as Version (elastic#29515) Enable license header exclusions (elastic#29379) Use proper Java version for BWC builds (elastic#29493) ...
Currently this fails because the Eclipse configuration splits the main and test folders into separate projects to avoid circular dependencies. Relates elastic#29336
Adds a
precommit
to every subprojects of:libs
that fails the buildif there are any
:libs
dependencies.I imagine it'd be possible to fail the build on startup if the
dependencies are unacceptable rather than use a precommit task but the
precommit task reports the error nicely and is easy to skip if for some
reason we want to temporarily skip it. So it felt like the right way to
go.
Since we now have three places where we resolve project substitutions
I've added
dependencyToProject
toproject.ext
in all projects. Itresolves both
project
style dependencies and "external" style (like"org.elasticsearch:elasticsearch-core:${version}") dependencies to
Project
s using theprojectSubstitutions
. I use this new function allthree places where resovle project substitutions.
Finally this pulls
apply plugin: 'elasticsearch.build'
out oflibs/*/build.gradle
and into a subprojects clause inlibs/build.gradle
. I do this entirely so that I can calltasks.precommit.dependsOn checkDependencies
without waiting for thesubprojects to be evaluated or worrying about whether or not they have
precommit
set up in a normal way.