Record Class AssignVersion

java.lang.Object
java.lang.Record
io.github.joke.conventionalversion.AssignVersion
All Implemented Interfaces:
Serializable, org.gradle.api.IsolatedAction<org.gradle.api.Project>

public record AssignVersion(VersionCatalogue catalogue) extends Record implements org.gradle.api.IsolatedAction<org.gradle.api.Project>
Assigns each project the version of the package that claims it.

A named record rather than a lambda, because isolated projects constrains what this action may close over and a lambda's captures are invisible: they are whatever happens to be in scope at the point it is written. Here the captured state is the catalogue, so it is declared, reviewed in a diff, and checked by the compiler. In particular this cannot capture the plugin instance, which a lambda calling an instance method silently would.

The other isolated-projects requirement - never touch another project's model - is visible in execute(Project): it uses the project it is handed and reaches nowhere else. Matching a project to its package is a lookup in a value computed before any project was evaluated, which is what keeps per-project versions compatible with isolated projects at all.

IsolatedAction extends Serializable, which is Gradle stating that requirement in the type system: every component of this record must be serializable, and VersionCatalogue is.

Public, and not by preference. Gradle 9.0 reconstructs a record by looking up its canonical constructor as a public member, so a package-private record fails to deserialize with NoSuchMethodException and every project configuration dies. Later versions look the constructor up as declared and do not care. The floor decides, so this is public.

See Also:
  • Constructor Details

    • AssignVersion

      public AssignVersion(VersionCatalogue catalogue)
      Creates an instance of a AssignVersion record class.
      Parameters:
      catalogue - the value for the catalogue record component
  • Method Details

    • execute

      public void execute(org.gradle.api.Project project)
      Specified by:
      execute in interface org.gradle.api.IsolatedAction<org.gradle.api.Project>
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • catalogue

      public VersionCatalogue catalogue()
      Returns the value of the catalogue record component.
      Returns:
      the value of the catalogue record component