Custom plugins: how to avoid using afterEvaluate when setting another plugin's extension configuration

Using afterEvaluate is not necessarily bad in this case. You need the project to be evaluated to know what was ultimately configured and act on it. The danger of afterEvaluate is really abuse where you have many things that are trying to execute later and later after each other when order is not guaranteed. As long as you’re handling the configuration of these plugins and eliminating bad coupling, you should be fine.

However, if you just really don’t want an afterEvaluate you could have the extension apply the plugins on the set of your value. The drawback is that if someone sets the value, then later changes it in the build.gradle file or through other means (like afterEvaluate abuse), you’ll have plugins you didn’t want.

1 Like