### Cat.avsc with inline enum definition Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md An example of a schema file using an inline type definition, which is generally discouraged in favor of modular files. ```json { "name": "Cat", "namespace": "example", "type": "record", "fields" : [ { "name": "breed", "type": { "name": "Breed", "type": "enum", "symbols" : [ "ABYSSINIAN", "AMERICAN_SHORTHAIR", "BIRMAN", "MAINE_COON", "ORIENTAL", "PERSIAN", "RAGDOLL", "SIAMESE", "SPHYNX" ] } } ] } ``` -------------------------------- ### Use com.github.davidmc24.gradle.plugin.avro-base for manual task configuration Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md Use the base plugin to manually define GenerateAvroJavaTask or GenerateAvroProtocolTask when default plugin behavior is insufficient. ```groovy import com.github.davidmc24.gradle.plugin.avro.GenerateAvroJavaTask apply plugin: "java" apply plugin: "com.github.davidmc24.gradle.plugin.avro-base" dependencies { implementation "org.apache.avro:avro:1.11.0" } def generateAvro = tasks.register("generateAvro", GenerateAvroJavaTask) { source("src/avro") outputDir = file("dest/avro") } tasks.named("compileJava").configure { source(generateAvro) } ``` -------------------------------- ### Apply the Avro plugin in build.gradle Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md Apply the plugin by adding the ID and version to the plugins block in build.gradle. ```groovy plugins { id "com.github.davidmc24.gradle.plugin.avro" version "VERSION" } ``` -------------------------------- ### Generate schema from IDL and protocol files Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md Uses GenerateAvroProtocolTask to convert IDL files to protocol files, followed by GenerateAvroSchemaTask to generate JSON schema files. ```groovy import com.github.davidmc24.gradle.plugin.avro.GenerateAvroProtocolTask import com.github.davidmc24.gradle.plugin.avro.GenerateAvroSchemaTask apply plugin: "com.github.davidmc24.gradle.plugin.avro-base" def generateProtocol = tasks.register("generateProtocol", GenerateAvroProtocolTask) { source file("src/main/avro") include("**/*.avdl") outputDir = file("build/generated-avro-main-avpr") } tasks.register("generateSchema", GenerateAvroSchemaTask) { dependsOn generateProtocol source file("src/main/avro") source file("build/generated-avro-main-avpr") include("**/*.avpr") outputDir = file("build/generated-main-avro-avsc") } ``` -------------------------------- ### Configure pluginManagement in settings.gradle Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md Define the plugin repositories in settings.gradle to allow the project to resolve the gradle-avro-plugin. ```groovy pluginManagement { repositories { gradlePluginPortal() mavenCentral() } } ``` -------------------------------- ### Configure createOptionalGetters Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md Set createOptionalGetters to true to generate additional getter methods that return fields wrapped in an Optional. ```groovy avro { createOptionalGetters = false } ``` -------------------------------- ### Configure conversionsAndTypeFactoriesClasspath Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md Use these properties to load custom Avro Conversion and LogicalTypeFactory classes from outside the build classpath by defining a custom configuration. ```groovy configurations { customConversions } dependencies { customConversions(project(":custom-conversions")) } avro { conversionsAndTypeFactoriesClasspath.from(configurations.customConversions) logicalTypeFactoryClassNames.put("timezone", "com.github.davidmc24.gradle.plugin.avro.test.custom.TimeZoneLogicalTypeFactory") customConversionClassNames.add("com.github.davidmc24.gradle.plugin.avro.test.custom.TimeZoneConversion") } ``` -------------------------------- ### Apply plugin in build.gradle.kts Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md Apply the plugin declaratively using the plugins block in your build.gradle.kts file. ```kotlin plugins { // Find latest release here: https://github.com/davidmc24/gradle-avro-plugin/releases id("com.github.davidmc24.gradle.plugin.avro") version "VERSION" } ``` -------------------------------- ### Configure templateDirectory Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md Overrides the default Avro templates by specifying a custom directory path. ```groovy avro { templateDirectory = "/path/to/velocity/templates" } ``` -------------------------------- ### Configure avro extension in Kotlin DSL Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md Use the avro block to configure plugin settings, ensuring properties are set using the .set() syntax. ```kotlin avro { isCreateSetters.set(true) isCreateOptionalGetters.set(false) isGettersReturnOptional.set(false) isOptionalGettersForNullableFieldsOnly.set(false) fieldVisibility.set("PUBLIC_DEPRECATED") outputCharacterEncoding.set("UTF-8") stringType.set("String") templateDirectory.set(null as String?) isEnableDecimalLogicalType.set(true) } ``` -------------------------------- ### Configure gettersReturnOptional Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md Set gettersReturnOptional to true to replace existing getter methods with versions that return Optional wrappers. ```groovy avro { gettersReturnOptional = false } ``` -------------------------------- ### Configure additionalVelocityToolClasses Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md Registers additional tools for use in custom Velocity templates. The provided classes must have a default constructor and will be accessible in templates via their simple class names. ```groovy avro { additionalVelocityToolClasses = ['com.yourpackage.Escape', 'com.yourpackage.JSON'] } ``` -------------------------------- ### Add Avro implementation dependency Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md Ensure the project has the necessary Avro library dependency to compile generated classes. ```groovy repositories { mavenCentral() } dependencies { implementation "org.apache.avro:avro:1.11.0" } ``` -------------------------------- ### Configure createSetters Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md Set createSetters to false to disable the generation of setter methods in the generated classes. ```groovy avro { createSetters = false } ``` -------------------------------- ### Configure fieldVisibility Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md Sets the visibility of fields in generated Java files. Defaults to PRIVATE. ```groovy avro { fieldVisibility = "PUBLIC" } ``` -------------------------------- ### Breed.avsc modular definition Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md The recommended approach for defining the Breed enum in its own file. ```json { "name": "Breed", "namespace": "example", "type": "enum", "symbols" : ["ABYSSINIAN", "AMERICAN_SHORTHAIR", "BIRMAN", "MAINE_COON", "ORIENTAL", "PERSIAN", "RAGDOLL", "SIAMESE", "SPHYNX"] } ``` -------------------------------- ### Configure stringType Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md Specifies the Java type used to represent Avro string types. Defaults to String. ```groovy avro { stringType = "CharSequence" } ``` -------------------------------- ### Configure outputCharacterEncoding Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md Controls the character encoding of generated Java files. Options include configuring the JavaCompile task or setting the encoding directly in the avro block. ```groovy // Option 1: configure compilation task (avro plugin will automatically match) tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' } // Option 2: just configure avro plugin avro { outputCharacterEncoding = "UTF-8" } ``` -------------------------------- ### Configure optionalGettersForNullableFieldsOnly Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md Use this in conjunction with gettersReturnOptional set to true to restrict Optional return types to only nullable field definitions. ```groovy avro { gettersReturnOptional = true optionalGettersForNullableFieldsOnly = true } ``` -------------------------------- ### Resolve Avro schema dependencies Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md Configures the ResolveAvroDependenciesTask to generate JSON schema with dependencies resolved from a specified source directory. ```groovy import com.github.davidmc24.gradle.plugin.avro.ResolveAvroDependenciesTask apply plugin: "com.github.davidmc24.gradle.plugin.avro-base" tasks.register("resolveAvroDependencies", ResolveAvroDependenciesTask) { source file("src/avro/normalized") outputDir = file("build/avro/resolved") } ``` -------------------------------- ### Cat.avsc modular definition Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md The recommended approach for defining the Cat record, referencing the Breed enum defined in a separate file. ```json { "name": "Cat", "namespace": "example", "type": "record", "fields" : [ {"name": "breed", "type": "Breed"} ] } ``` -------------------------------- ### Configure enableDecimalLogicalType Source: https://github.com/davidmc24/gradle-avro-plugin/blob/master/README.md Disables the use of java.math.BigDecimal for decimal logical types, causing the plugin to use java.nio.ByteBuffer instead. ```groovy avro { enableDecimalLogicalType = false } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.