Gradle DSL polygon definition | polygonal-architecture plug-in

The one of existing option to create polygon definition is Gradle DSL.

Previous page

Gradle DSL configuration

The example gradle DSL configuration might looks like this one:

// build.gradle 
polygonalArchitecture {
  sourcesDir = file('src/main/java')
  basePackage = 'org.example'
  
  polygon {
    packageDef {
      publicScope = 0
      packagePrivateScope = -1
      types = ['interface', 'class', 'enum']
    }
    packageDef {
      name = 'dto'
      required = true
      publicScope = -1
      types = ['class']
    }
    packageDef {
      name = 'ports'
      publicScope = -1
      types = ['interface']
    }
    packageDef {
      name = 'queries'
      packagePrivateScope = -1
      types = ['class']
    }
    packageDef {
      name = 'commands'
      packagePrivateScope = -1
      types = ['class']
    }
  }
} 

The full list of allowed attributes:

DSL atribute Description Default
sourcesDir Relative path to the sources. Required file('src/main/java')
basePackage The level0 / package where polygons are stored. Your polygonal architecture starts here. Required ``
strictMode If true, only defined packages are allowed. false
polygonTemplate Template file -> if you’d like to keep polygon definition in .yml file. Required if polygon dsl is not defined null
polygon Polygon gradle dsl configuration. Required if polygonTemplate is not defined null
polygon.packageDef The polygon package rules definition.  
polygon.packageDef.name The name of the package. The nested packages like abc.defg are allowed. '', it’s root level definition
polygon.packageDef.required If true, definied packages is required inside polygon. false
polygon.packageDef.publicScope How many public scope objects are allowed. -1 unlimited, 0 not allowed, n n allowed 0
polygon.packageDef.packagePrivateScope How many public scope objects are allowed. -1 unlimited, 0 not allowed, n n allowed 0 (-1 for root level)
polygon.packageDef.protectedScope How many public scope objects are allowed. -1 unlimited, 0 not allowed, n n allowed 0
polygon.packageDef.internalScope How many internal scope objects are allowed. -1 unlimited, 0 not allowed, n n allowed 0
polygon.packageDef.types What types are allowed. Available values are ['interface', 'class', 'enum', 'abstract class', 'data class', 'open class'] ['interface', 'class', 'enum', 'abstract class']