Skip to content

Commit f39393a

Browse files
authored
Merge pull request #16219 from Ekatereana/BAEL-7445-gradle-avro-code-generation
BAEL-7445, gradle avro code generation
2 parents 0bc686a + 63df143 commit f39393a

13 files changed

Lines changed: 531 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# Linux start script should use lf
5+
/gradlew text eol=lf
6+
7+
# These are Windows script files and should use crlf
8+
*.bat text eol=crlf
9+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore Gradle project-specific cache directory
2+
.gradle
3+
4+
# Ignore Gradle build output directory
5+
build
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## Relevant Articles
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
buildscript {
2+
dependencies {
3+
classpath libs.avro.tools
4+
}
5+
}
6+
7+
plugins {
8+
id 'java'
9+
alias libs.plugins.avro
10+
}
11+
12+
repositories {
13+
mavenCentral()
14+
}
15+
16+
dependencies {
17+
implementation libs.avro
18+
// Use JUnit Jupiter for testing.
19+
testImplementation libs.junit.jupiter
20+
21+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
22+
23+
}
24+
25+
import org.apache.avro.tool.SpecificCompilerTool
26+
27+
sourceCompatibility = JavaVersion.VERSION_21
28+
targetCompatibility = JavaVersion.VERSION_21
29+
30+
def avroSchemasDir = "src/main/custom"
31+
def avroCodeGenerationDir = "build/generated-main-avro-custom-java"
32+
33+
// Add the generated Avro Java code to the Gradle source files.
34+
sourceSets.main.java.srcDirs += [avroCodeGenerationDir]
35+
36+
tasks.register('customAvroCodeGeneration') {
37+
// Define the task inputs and outputs for the Gradle up-to-date checks.
38+
inputs.dir(avroSchemasDir)
39+
outputs.dir(avroCodeGenerationDir)
40+
// The Avro code generation logs to the standard streams. Redirect the standard streams to the Gradle log.
41+
logging.captureStandardOutput(LogLevel.INFO);
42+
logging.captureStandardError(LogLevel.ERROR)
43+
doLast {
44+
// Run the Avro code generation.
45+
new SpecificCompilerTool().run(System.in, System.out, System.err, List.of(
46+
"-encoding", "UTF-8",
47+
"-string",
48+
"-fieldVisibility", "private",
49+
"-noSetters",
50+
"schema", "$projectDir/$avroSchemasDir".toString(), "$projectDir/$avroCodeGenerationDir".toString()
51+
))
52+
}
53+
}
54+
55+
tasks.withType(JavaCompile).configureEach {
56+
// Make Java compilation tasks depend on the Avro code generation task.
57+
dependsOn('customAvroCodeGeneration')
58+
}
59+
60+
tasks.named('test') {
61+
// Use JUnit Platform for unit tests.
62+
useJUnitPlatform()
63+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This file was generated by the Gradle 'init' task.
2+
# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format
3+
4+
[versions]
5+
junit-jupiter = "5.10.0"
6+
avro = "1.11.0"
7+
8+
[libraries]
9+
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
10+
avro = {module = "org.apache.avro:avro", version.ref = "avro"}
11+
avro-tools = {module = "org.apache.avro:avro-tools", version.ref = "avro"}
12+
13+
[plugins]
14+
avro = { id = "com.github.davidmc24.gradle.plugin.avro", version = "1.9.1" }
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

gradle-modules/gradle-customization/gradle-avro/gradlew

Lines changed: 249 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)