From af272076aeac59b3ffded0845b2ec72319d4b95a Mon Sep 17 00:00:00 2001 From: Kristof Jozsa Date: Thu, 3 Oct 2024 18:17:30 +0200 Subject: [PATCH] fineract-avro-schemas module turned to kotlin dsl --- fineract-avro-schemas/build.gradle.kts | 98 +++++++++++++++++++ .../{build.gradle => build.gradle.off} | 0 fineract-avro-schemas/dependencies.gradle | 21 ---- 3 files changed, 98 insertions(+), 21 deletions(-) create mode 100644 fineract-avro-schemas/build.gradle.kts rename fineract-avro-schemas/{build.gradle => build.gradle.off} (100%) delete mode 100644 fineract-avro-schemas/dependencies.gradle diff --git a/fineract-avro-schemas/build.gradle.kts b/fineract-avro-schemas/build.gradle.kts new file mode 100644 index 00000000000..42fc733e39b --- /dev/null +++ b/fineract-avro-schemas/build.gradle.kts @@ -0,0 +1,98 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +// TODO: @vidakovic we should publish this lib to Maven Central; do in separate PR + +plugins { + java + id("com.github.davidmc24.gradle.plugin.avro-base") version "1.9.1" +} + +description = "Fineract Avro Schemas" + +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} + +dependencies { + implementation("org.apache.avro:avro") +} + +//tasks.withType { +// options.compilerArgs.add("-Werror") +//} + +val avroSourceDir = "$projectDir/src/main/avro" +val avroPreProcessedDir = layout.buildDirectory.dir("generated/avro/src/main/avro") +val avroGeneratedSourcesDir = layout.buildDirectory.dir("generated-src/avro/main") + +tasks.register("preprocessAvroSchemas") { + inputs.dir(avroSourceDir) + outputs.dir(avroPreProcessedDir) + + doLast { + println("## preprocessing Avro schemas...") + copy { + from(avroSourceDir) + into(avroPreProcessedDir) + filter { line: String -> + line.replace("\"bigdecimal\"", file("$projectDir/src/main/resources/avro-templates/bigdecimal.avsc").readText(Charsets.UTF_8)) + } + } + } +} + +tasks.register("generateAvroJava") { + println("## generating Avro Java sources...") + dependsOn("preprocessAvroSchemas") + inputs.dir(avroPreProcessedDir) + outputs.dir(avroGeneratedSourcesDir) + + source(avroPreProcessedDir) + setOutputDir(file(avroGeneratedSourcesDir)) +} + +sourceSets { + main { + java.srcDir(avroGeneratedSourcesDir) + } +} + +tasks.named("compileJava") { + dependsOn("preprocessAvroSchemas", "generateAvroJava", "spotlessJsonApply") +} + +spotless { + json { + target("**/*.avsc") + simple() + } +} + +tasks.register("cleanGeneratedSources") { + delete(avroPreProcessedDir, avroGeneratedSourcesDir) +} + +tasks.named("clean") { + dependsOn("cleanGeneratedSources") +} + +tasks.named("licenseMain") { + dependsOn(tasks.named("generateAvroJava")) +} diff --git a/fineract-avro-schemas/build.gradle b/fineract-avro-schemas/build.gradle.off similarity index 100% rename from fineract-avro-schemas/build.gradle rename to fineract-avro-schemas/build.gradle.off diff --git a/fineract-avro-schemas/dependencies.gradle b/fineract-avro-schemas/dependencies.gradle deleted file mode 100644 index aac8795c3be..00000000000 --- a/fineract-avro-schemas/dependencies.gradle +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -dependencies { - implementation('org.apache.avro:avro') -}