Get extension object and conditionally apply plugin

Hey everyone,

my questions is about writing custom gradle plugins with java.
I am providing a configuration closure within my plugin:

project.getExtensions().create(closureName, aClass);

Depending on how the user configures the extension, I want to apply a plugin to the target project.

But when I load the extension object, it is always null:

AutoVersionConfig extractedCfg = project.getExtensions().findByType(AutoVersionConfig.class);

I can get the correct extension object after project evaluation (project.afterEvaluate) but can’t apply a plugin anymore at this time.

How can I achieve what I described?

Thanks in advance