This message was deleted.
# community-support
s
This message was deleted.
e
I would expect
Copy code
buildscript {
    dependencies {
        constraints {
            classpath(...)
to work
v
It should if done properly. Also see https://blog.gradle.org/log4j-vulnerability
m
@Vampire - not sure if I am missing something, but doing
constraints
did not work on dependencies pulled in by the plugins (works fine for normal dependencies, but if it is coming from a plugin, it seems to be ignored
v
As you can see in the blog post, it works fine, so maybe you should provide an MCVE 🙂
(given the information in the blog is correct of course)
m
weird, we use this for managing transitive vulnerable dependencies in our project, and that works fine, but when I tried to do this to a dependency pulled in via a plugin it seems to have ignored it
I tried to add it in
settings.gradle's
pluginManagement section, but it refused to recognize the constraints directive
e
if you want it in
settings.gradle
, try
Copy code
gradle.beforeProject {
    buildScript {
        ...
v
That wouldn't help much for settings plugins though. But simply using
buildscript { ... }
there should also work
e
right, you'd need it in the body of the settings script too
v
Btw. @ephemient are you aware of a difference between
gradle.allprojects { ... }
and
gradle.beforeProject { ... }
when called from a settings script?
e
I didn't check at what point
allprojects
runs
v
Should run immediately for all projects already there and on newly added ones as soon as they are added. But I think either way before the actual build scripts come into play if I'm not remembering wrongly.
e
in any case, these constraints aren't inherited from parent to child so you need to apply to all projects afaik
m
I am clearly missing something - what is the significance of
buildScript
- I thought this is some legacy statement (a lot of instructions mentioning say to use it only with older gradle) , but I starting to think I am wrong
v
That is wrong, yes
m
wouldnt be the first time
v
You should not use it to add plugins to the classpath and then apply them using the legacy mechanism
For that you should use the
plugins { ... }
block.
But it is fine to declare dependencies you directly use in the buildscript or to declare dependency constraints for example.
Besides that the need to do the former is a sign that you should move that logic to a custom plugin or custom task instead 🙂
e
also if you have a plugin that doesn't have a proper marker, you have to either add the dependency in buildscript (or add resolution rules to pluginManagement). that works together with the plugins block, it's not a full replacement
m
ok - I am still a bit confused about constraints for plugin - do I need to do this as :
Copy code
// in build.gradle
buildScript {
  dependencies {
    constraints {
       ...
    }
  }
}
?
v
yes
e
that works but only for plugins applied in that project (not other subprojects)
v
of course
It's
buildscript { ... }
not
buildscriptHierarchy { ... }
😄
(Don't try to use that, I made it up)
e
buildscript { dependencies { classpath(...) } }
is inherited by child subprojects
m
For now I just want to get the parent project to work 😄
v
buildscript { dependencies { classpath(...) } }
is inherited by child subprojects
Only kind of. It is not really inherited. It only works on the classpath of the current build script. This classpath lands on a class loader. This class loader is the parent of the class loader of the child project buildscript class loader. And as class loaders first have to ask their parent for a class before serving it themselves, the one would win. But on the class loader of the child project you could still have the a different version, maybe with vulnerabilities and so on. 🙂
e
"kind of" sure, it's classloader inheritance and not extending the buildscript configuration but classloaders load from their parent first, so even if you add a different versioned dependency in a child project's buildscript, for any classes that exist in the parent, you'll get that instead of whatever the child requested
so normally a child project can't add vulnerabilities just by bringing in a dependency different than the parent, unless the issue is in new classes that don't exist in the other version and also somehow don't crash when mixed with old classes
definitely can lead to some unintuitive behavior where the output of
:buildEnvironment
doesn't match what's actually on the classpath though
v
You never know what people come up with to use vulnerabilities. The vulnerable jar will be already present and can maybe easily be used by evil-doers. 🤷‍♂️
e
I wonder if it's in the realm of feasibility for project isolation to break that parent classpath connection and instead use the parent as a "dependency"