I ran into this problem too while my demand was to generate dto into a certain package in src/main/java (Springboot 3.3.2, java21 graalvm, gradle8.9 ).
{
"type": "record",
"name": "DemoDTO",
"namespace": "com.****.sp.domain.dto",
"fields":[
{"name": "param0", "type": "string"},
{"name": "param1", "type": "string"},
{"name": "param2", "type": "string"}
]
}
Configurations from davidmc24/gradle-avro-plugin may still adds up, though it truly is not maintained anymore =/ (seems like it should take a while before a apache release)
Here is my solution:
- Create avro config package under src/main/avro (default file path referenced when generating).
- Add the plugin into
build.gradle
that allows you to do some custom stuff but don't keep the basic plugin for it would generate avro classes as well in the default avro output directory($buildDir/generated-main-avro-java
) when building, which finally causes duplicate class error during compileJava
.
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.2'
id 'io.spring.dependency-management' version '1.1.6'
id 'org.graalvm.buildtools.native' version '0.10.2'
id 'com.github.davidmc24.gradle.plugin.avro-base' version '1.3.0'
// id 'com.github.davidmc24.gradle.plugin.avro' version '1.3.0'
}
- Simply copy-paste those configuration then let the gradle build
import com.github.davidmc24.gradle.plugin.avro.GenerateAvroJavaTask
apply plugin: "java"
apply plugin: "com.github.davidmc24.gradle.plugin.avro-base"
def generateAvro = tasks.register("generateAvro", GenerateAvroJavaTask) {
source("src/main/avro")
outputDir = file("src/main/java")
}
tasks.named("compileJava").configure {
source(generateAvro)
}
- Build successful =u=