Weird behavior in project.afterEvaluate when move from 7.5 to 8.0 version

Hello,

We are trying to move from Gradle 7.5 to 8.0.
We are having problems with a plugin when we try to recover several extension properties.
In our build.gradle file, we have an structure like:

Object1 {
	propertie1 "value1"	
	object2 {
		propertie2 "value2"
		propertie3 "value3"
		propertie4 "value4"
	}
}

In the plugin code, we are doing:

public void apply(Project project) {
	NamedDomainObjectContainer<DocumentResource> resources = project.container(DocumentResource.class);
	Object1 extension = project.getExtensions().create("Object1", Object1.class, project, resources);
	project.afterEvaluate(action -> {
		System.out.println(extension.getPropertie1());
		System.out.println(extension.getobject2());

With Gradle 7.5 the code works ok and both values are present, but with 8.0 version, second value is null; even more, if we modify the the order in build.gradle file, defining the object2 before propertie1, in 8.0 version both values are null.

Any idea about how to solve it?

Hard to say without having a hands-on example project.

But actually the best solution always is to get rid of the need to use afterEvaluate at all, and instead use Properties for values, or methods in the extension if you need to react to values being set.

Finally we solved the issue adding in the Object1 constructor the last code line:

public class Object1 {
    NamedDomainObjectContainer<Object3> resources;
    private Project project;
    private String propertie1;
    private Object2 object2;
    
    public Object1(Project project, NamedDomainObjectContainer<Object3> resources) {
        this.project = project;
        this.resources = resources;
        this.object2 = project.getExtensions().create("Object2", Object2.class, project);
    }