From 5595cab1827abeaa02745b1c0ab97ef52065575d Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Mon, 29 Jul 2024 10:05:47 -0300 Subject: [PATCH] add ktlint.gradle file --- .../kotlin/templates/gradle/kotlin.gradle.ejs | 8 ------ .../__snapshots__/generator.spec.js.snap | 8 ++++++ generators/ktlint/generator.js | 7 +++++- .../ktlint/templates/gradle/ktlint.gradle.ejs | 25 +++++++++++++++++++ 4 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 generators/ktlint/templates/gradle/ktlint.gradle.ejs diff --git a/generators/kotlin/templates/gradle/kotlin.gradle.ejs b/generators/kotlin/templates/gradle/kotlin.gradle.ejs index 6b7168450..cca226988 100644 --- a/generators/kotlin/templates/gradle/kotlin.gradle.ejs +++ b/generators/kotlin/templates/gradle/kotlin.gradle.ejs @@ -61,11 +61,6 @@ allOpen { } } -ktlint { - //See more options: https://github.com/JLLeitschuh/ktlint-gradle#configuration - ignoreFailures = true -} - if (OperatingSystem.current().isWindows()) { bootRun { doFirst { @@ -74,9 +69,6 @@ if (OperatingSystem.current().isWindows()) { } } -// Reformat code before compilation -compileKotlin.dependsOn ktlintFormat - jacocoTestReport { // Add Kotlin sources to Jacoco source dirs sourceDirectories.from += sourceSets.main.kotlin.srcDirs diff --git a/generators/ktlint/__snapshots__/generator.spec.js.snap b/generators/ktlint/__snapshots__/generator.spec.js.snap index 705b1b6cc..bcb386f08 100644 --- a/generators/ktlint/__snapshots__/generator.spec.js.snap +++ b/generators/ktlint/__snapshots__/generator.spec.js.snap @@ -12,6 +12,11 @@ exports[`SubGenerator kotlin of kotlin JHipster blueprint > gradle > should matc }, ], ], + "applyFromGradle": [ + { + "script": "gradle/ktlint.gradle", + }, + ], } `; @@ -20,6 +25,9 @@ exports[`SubGenerator kotlin of kotlin JHipster blueprint > gradle > should succ ".yo-rc.json": { "stateCleared": "modified", }, + "gradle/ktlint.gradle": { + "stateCleared": "modified", + }, "package.json": { "stateCleared": "modified", }, diff --git a/generators/ktlint/generator.js b/generators/ktlint/generator.js index d57ed7676..f228ca59f 100644 --- a/generators/ktlint/generator.js +++ b/generators/ktlint/generator.js @@ -96,7 +96,10 @@ export default class extends BaseApplicationGenerator { return this.asWritingTaskGroup({ async writing({ application }) { await this.writeFiles({ - blocks: [{ templates: ['.gitignore.jhi.ktlint'] }], + blocks: [ + { templates: ['.gitignore.jhi.ktlint'] }, + { condition: ctx => ctx.buildToolGradle, templates: ['gradle/ktlint.gradle'] }, + ], context: application, }); }, @@ -122,6 +125,8 @@ export default class extends BaseApplicationGenerator { }, addDependencies({ application, source }) { if (application.buildToolGradle) { + source.applyFromGradle({ script: 'gradle/ktlint.gradle' }); + source.addGradleDependencyCatalogPlugins([ { pluginName: 'ktlint', diff --git a/generators/ktlint/templates/gradle/ktlint.gradle.ejs b/generators/ktlint/templates/gradle/ktlint.gradle.ejs new file mode 100644 index 000000000..617d78f5d --- /dev/null +++ b/generators/ktlint/templates/gradle/ktlint.gradle.ejs @@ -0,0 +1,25 @@ +<%# + Copyright 2013-2024 the original author or authors from the JHipster project. + + This file is part of the JHipster project, see https://www.jhipster.tech/ + for more information. + + Licensed 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. +-%> +ktlint { + //See more options: https://github.com/JLLeitschuh/ktlint-gradle#configuration + ignoreFailures = true +} + +// Reformat code before compilation +compileKotlin.dependsOn ktlintFormat