Gradle plugins

KlumAST provides some Gradle plugins to make the setup of a Klum project easier. They consist of the following plugins:

com.blackbuild.convention.groovy

This plugin is not specific to Klum and might be extracted to a separate project in the future. It basically sets the necessary dependencies for Groovy as well as a matching version of the Spock Framework.

The version can be set directly via a String or int property:

plugins {
    id 'com.blackbuild.convention.groovy' version '<version>'
    id 'groovy'
}

groovyDependencies {
    groovyVersion = 3 // or "5.0.5"
}

Note that the plugin does not apply the groovy plugin; it only reacts to its presence.

Applying the plugin (provided the Groovy plugin is also applied) does the following thing:

If the plugin is applied to a child project, it will inherit the configured Groovy versions from the root project, if applicable (even if the Groovy plugin is not applied to the root project). That way, the Groovy version can be set in a single place. In a klum project, this is usually the only situation where the convention plugin needs to be used directly, as the other two plugins will apply it automatically.

com.blackbuild.klum-ast-schema

This plugin is used in schema projects (as well as api as defined by [Layer3]). It does the following things:

Named Schema modules

The Schema plugin validates a user-owned src/main/java/module-info.java through validateKlumSchemaModule. It is included in check and, when maven-publish is applied, before Maven publication. The task never edits the descriptor.

Groovy 4 and 5 may use a named Schema module. Its descriptor requires the annotations and runtime modules, requires static com.blackbuild.klum.ast.compiler, and org.apache.groovy; when the project declares the Jackson or Bean Validation adapter, it must also require that adapter and open each Schema package to its reflection target. See Migration#named-modules-and-groovy for a complete descriptor example.

Groovy 3 is classpath-only for KlumAST Schema projects. If it finds a descriptor, the validation task fails with a copyable remediation: remove module-info.java and use the ordinary classpath, or move the Schema to Groovy 4 or 5. Do not add --add-reads, --add-exports, --patch-module, or similar workaround flags. Generated Foo_DSL mirrors remain IntelliJ metadata, never module sources.

This means that a fully working schema project can be set up with the following minimal build.gradle:

plugins {
    id 'com.blackbuild.klum-ast-schema' version '4.0.0'
    id "maven-publish"
}

publishing {
    repositories {...}
}

com.blackbuild.klum-ast-model

This plugin is used in model projects. It does the following things:

A simple model project can look like:

plugins {
    id 'com.blackbuild.klum-ast-model' version '4.0.0'
    id "maven-publish"
}

klumModel {
    groovyVersion = "3" // default
    schemas {
        schema "my-group:my-schema:1.0"
    }
    topLevelScript "my.group.schema.Configuration", "model.Configuration"
    topLevelScript "my.group.schema.server.Target", "model.server.Targets"
}

Multi module

Schema and model can be combined in a multimodule project (with the pre mentioned problem of missing IDE support): Because the root project applies the shared convention plugin at the matching KlumAST version, its child Schema and Model projects can use the packaged plugin IDs without repeating that version.

Root:

plugins {
    id 'com.blackbuild.convention.groovy' version '4.0.0'
}

groovyDependencies {
    groovyVersion = "3"
}

Schema:

plugins {
    id 'com.blackbuild.klum-ast-schema'
}

Model:

plugins {
    id 'com.blackbuild.klum-ast-model'
}

klumModel {
    schemas {
        schema project(":schema")
    }
    topLevelScript "my.group.schema.Configuration", "model.Configuration"
    topLevelScript "my.group.schema.server.Target", "model.server.Targets"
}