What is the difference between inheritance and configuration injection?


(Ryan Nelson) #1

The Gradle docs state (49.9):

Properties and methods declared in a project are inherited to all its subprojects. This is an alternative to configuration injection. But we think that the model of inheritance does not reflect the problem space of multi-project builds very well. In a future edition of this user guide we might write more about this.

I understand what configuration injection is doing in principle, but I’d like to understand more about the distinctions from inheritance, and why it’s a better fit for multi-project builds.

Can anyone give me a few bullets on this?

http://gradle.org/docs/current/userguide/userguide_single.html#sec%3Aproperty_and_method_inheritance


(Peter Niederwieser) #2

Configuration injection is an equally concise yet more flexible and explicit mechanism than configuration inheritance (as used by build tools like Maven). Instead of applying all configuration to all subprojects, it allows you to apply any configuration to any set of subprojects. This lets you accurately express commonalities and differences between projects.


(Ryan Nelson) #3

Thanks, Peter. I reviewed the docs and see that I missed the discussion on applying configuration to a single project (I only noticed allprojects and subprojects). That’s clearer now.


(Peter Niederwieser) #4

You can apply configuration to any subset of projects.


(Luke Daley) #5

One other difference is that configuration can be injected from any direction, not just parent

→ child.