Never build auth again! The Okta Developer Platform makes it simple to implement authentication, authorization, MFA and more in Java applications. Get started with the free API.

When we use rule-based model configuration in our Gradle project, we can give Gradle rules on how to manage objects from the model space. These rules are defined in a class that extends RuleSource. When we want to set some default values for properties of a model object (in Gradle terms this is a subject) we can use the @Defaults annotation. Rules annotated with @Defaults are invoked right after the object is created and before any other methods that can mutate the state of the object.

The method, to set the default values, must have the type of the object as the first parameter. Other parameters are considered input parameters and can be used to set a default value based on other model objects.

In a previous post, we worked with a managed object VersionFile. Let's add a default value for the version property. We want the version default value to be the unspecified: