I want to create a separate (groovy) gradle file t...
# community-support
a
I want to create a separate (groovy) gradle file that contains a single configuration closure (sorry if my terminology isn't right here). I want to apply it into the main build.gradle file, but I want to ensure that only the one configuration gets applied and anything else that may be defined in that new file should be ignored. Is this possible? I'm struggling to find the answer to this on google. So in the new file, I intend on having
Copy code
foo {
  bar = "baz"
}
and want the main build.gradle to only apply that "foo" configuration, even if the new file contained:
Copy code
foo {
  bar = "baz"
}

blah {
  blah = "blah"
}
I'd be okay with gradle throwing an error or simply ignoring the extra content if it exists
v
I don't think you can do that, except maybe if you wrap the configuration in a function you then call. But you can then as well just split it into multiple files. Maybe if you would share the actual use-case, there would be further recommendations. Besides that, assuming you then want to use it with apply-from, you should think thrice before you do. Those are called legacy script plugins and are highly discouraged due to quite some quirks in using them. Better have a look at convention plugins instead if you want to reuse or centralize build logic, for example implemented in`buildSrc` or an included build, for example using pre-compiled script plugins which look almost like normal build scripts.
👍 1