Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inherit behavior in Gradle?

Tags:

maven

gradle

I am a Gradle newbie and a somewhat experienced Maven hand. While thus far I like Gradle, there is already a feature of Maven that I am missing - either because it doesn't exist, or because I haven't found it, or because it is called something else.

In Maven there is a concept of inheritance, by which one POM can inherit properties and certain behaviors from a parent, and since parent POMs can also have parents, from a grandparent POM, etc. By this means it is possible to templatize bits of build behavior. This is something I want to be able to do, as I am in the process of designing a replacement for an old and crusty build system (which called things like these "rules"). Any such property or behavior defined in the Maven parent could be overwritten in the child.

Can someone point me at where I might find a similar concept in Gradle?

I've been all over the docs without seeing precisely what I'm after, but maybe I'm missing it? I looked at Gradle's comparison chart and found the "Named Domain Objects Container", described as a "very powerful feature" but the link points to a javadoc, not to examples of how it might be used.
Then there's the "Multiple Mix-Ins for Pre-Configuring Builds" which also sounds interesting but again without any examples.

Thanks in advance to anyone who can help.

Update: I'm repeating here what I said in a comment below to emphasize what I'm trying to accomplish here:

In my situation, there are hundreds of multi-build projects, whose subprojects mostly fall into one of several categories, each of which has consistent structures and assumptions (about directory structure, rpm scripts used, etc.) I don't want to store all this consistency in the parent (where it would need to be repeated in every parent project) but in some "meta-layer" living at the level of all the parent projects and accessible to all their child projects. This accessibility should probably be implemented through the parent projects, but should NOT reside there.

like image 275
Steve Cohen Avatar asked Oct 30 '22 10:10

Steve Cohen


1 Answers

The answer appears to be Initialization Scripts.

These run before any build is run and can be used to set up defaults. In any case, they do what I need them to do.

like image 129
Steve Cohen Avatar answered Jan 04 '23 14:01

Steve Cohen