diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 2713121..5ff4752 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -10,14 +10,15 @@ updates: rebase-strategy: auto schedule: interval: "daily" - day: "sunday" commit-message: prefix: "[gradle]" + groups: + gradle-patch-updates: + update-types: [ "patch" ] - package-ecosystem: "github-actions" directory: "/" rebase-strategy: auto schedule: interval: "weekly" - day: "sunday" commit-message: prefix: "[github-actions]" \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5a08940..0a9d0d5 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,11 +6,8 @@ on: pull_request: branches: [ main ] -permissions: - contents: read - env: - GRADLE_OPTS: "-Dorg.gradle.console=plain" + GRADLE_OPTS: "-Dorg.gradle.console=plain -Dorg.gradle.caching=true -Dkotlin.caching.enabled=true" jobs: compile: @@ -19,11 +16,14 @@ jobs: steps: - uses: actions/checkout@v4 - uses: Liber-UFPE/spring-gradle-build-action@v2 - - name: Validate Gradle wrapper - uses: gradle/wrapper-validation-action@v1 - - name: Starts Gradle Daemon - run: ./gradlew + with: + # Runs the gradle wrapper step + gradle-wrapper-validation: true + # Allows this job to write to the cache every time it runs + gradle-cache-read-only: false - run: ./gradlew testClasses + - name: Gradle Tasks Summary + run: cat build/reports/build-times.md >> $GITHUB_STEP_SUMMARY detekt: name: Code Analysis / detekt @@ -33,7 +33,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: detekt report - uses: natiginfo/action-detekt-all@1.23.1 + uses: natiginfo/action-detekt-all@1.23.3 with: args: | --report md:build/reports/detekt/detekt.md @@ -53,23 +53,6 @@ jobs: - name: run ktlin run: ktlint --relative >> $GITHUB_STEP_SUMMARY - accessibility-test: - name: Tests / Accessibility - runs-on: ubuntu-latest - # Since this job is experimental - continue-on-error: true - needs: - - detekt - - ktlint - steps: - - uses: actions/checkout@v4 - - uses: Liber-UFPE/spring-gradle-build-action@v2 - - run: ./gradlew accessibilityTestClasses - - name: Run Accessibility Tests - # For some annoying reason, Gradle insists in execute the `test` task - # too. -x removes it from the task graph for this execution. - run: ./gradlew accessibilityTest - test: name: Tests / test runs-on: ubuntu-latest @@ -79,7 +62,10 @@ jobs: steps: - uses: actions/checkout@v4 - uses: Liber-UFPE/spring-gradle-build-action@v2 - - run: ./gradlew koverHtmlReport -x accessibilityTest + - name: Run tests + run: ./gradlew koverHtmlReport -x accessibilityTest + - name: Gradle Tasks Summary + run: cat build/reports/build-times.md >> $GITHUB_STEP_SUMMARY - name: Setup Pandoc uses: r-lib/actions/setup-pandoc@v2 - name: Output Kover summary @@ -98,8 +84,8 @@ jobs: output-to: "step-summary" only-summary: "true" - build: - name: Package / build + shadowJar: + name: Package / shadowJar runs-on: ubuntu-latest needs: - test @@ -107,6 +93,8 @@ jobs: - uses: actions/checkout@v4 - uses: Liber-UFPE/spring-gradle-build-action@v2 - run: ./gradlew shadowJar + - name: Gradle Tasks Summary + run: cat build/reports/build-times.md >> $GITHUB_STEP_SUMMARY build-docker: name: Package / Docker / build @@ -118,6 +106,26 @@ jobs: - uses: Liber-UFPE/spring-gradle-build-action@v2 - name: Run dockerBuild run: ./gradlew dockerBuild + - name: Gradle Tasks Summary + run: cat build/reports/build-times.md >> $GITHUB_STEP_SUMMARY + + build-docker-native: + name: Package / Docker / native + runs-on: ubuntu-latest + needs: + - test + steps: + - uses: actions/checkout@v4 + - name: Setup GraalVM + uses: graalvm/setup-graalvm@v1 + with: + java-version: '21' + distribution: 'graalvm' + cache: 'maven' + - name: Run dockerBuildNative + run: GRAALVM_QUICK_BUILD=true ./gradlew dockerBuildNative + - name: Gradle Tasks Summary + run: cat build/reports/build-times.md >> $GITHUB_STEP_SUMMARY check-if-prod: if: ${{ github.ref == 'refs/heads/main' }} @@ -150,6 +158,8 @@ jobs: - uses: Liber-UFPE/spring-gradle-build-action@v2 - name: Create Release Package run: ./gradlew clean shadowJar + - name: Gradle Tasks Summary + run: cat build/reports/build-times.md >> $GITHUB_STEP_SUMMARY - name: Create Github Release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 0000000..dbef79c --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,32 @@ +name: 'Gradle Build Action' +description: 'Reusable GitHub Action for performing a gradle build or running a gradle task.' + +inputs: + gradle-cache-disabled: + description: 'Caching is enabled by default. You can disable caching for the action using this parameter' + required: false + default: false + gradle-cache-read-only: + description: 'Configure read-only caching for the gradle-build-action' + required: false + default: ${{ github.ref != 'refs/heads/main' }} + gradle-cache-write-only: + description: 'Configure write-only caching for the gradle-build-action' + required: false + default: false + +runs: + using: 'composite' + steps: + - name: Set up JDK 21 + uses: actions/setup-java@v3 + with: + java-version: "21" + distribution: "temurin" + - name: Set up Gradle + uses: gradle/gradle-build-action@v2 + with: + generate-job-summary: false + cache-disabled: ${{ inputs.gradle-cache-disabled }} + cache-read-only: ${{ inputs.gradle-cache-read-only }} + cache-write-only: ${{ inputs.gradle-cache-write-only }} diff --git a/.github/workflows/lighthouse-cron.yml b/.github/workflows/lighthouse-cron.yml new file mode 100644 index 0000000..d77f546 --- /dev/null +++ b/.github/workflows/lighthouse-cron.yml @@ -0,0 +1,36 @@ +name: Lighthouse CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + schedule: + # every day at 1am + - cron: "0 1 * * *" + +env: + GRADLE_OPTS: "-Dorg.gradle.console=plain -Dorg.gradle.caching=true -Dkotlin.caching.enabled=true" + +jobs: + lighthouse-ci: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + # 0 indicates all history for all branches and tags. + fetch-depth: 0 + - uses: Liber-UFPE/spring-gradle-build-action@v2 + - uses: actions/setup-node@v4 + with: + node-version: 18 # lts version + check-latest: true + - name: Install Lighthouse CI + run: npm install -g @lhci/cli + - name: Run Lighthouse CI + run: lhci autorun + env: + PROJECT_TOKEN: ${{ vars.LHCI_PROJECT_TOKEN }} + GITHUB_TOKEN: ${{ secrets.LHCI_GITHUB_TOKEN }} + BASIC_AUTH_USERNAME: ${{ secrets.LHCI_BASIC_AUTH_USERNAME }} + BASIC_AUTH_PASSWORD: ${{ secrets.LHCI_BASIC_AUTH_PASSWORD }} \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3eea88d..834e65f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,7 @@ permissions: contents: write env: - GRADLE_OPTS: "-Dorg.gradle.console=plain" + GRADLE_OPTS: "-Dorg.gradle.console=plain -Dorg.gradle.caching=true -Dkotlin.caching.enabled=true" jobs: gh-dependency-graph: @@ -26,4 +26,6 @@ jobs: with: dependency-graph: generate-and-submit - name: Generate Dependency Graph - run: ./gradlew compileTestKotlin + run: ./gradlew testClasses + - name: Gradle Tasks Summary + run: cat build/reports/build-times.md >> $GITHUB_STEP_SUMMARY diff --git a/.gitignore b/.gitignore index e21169a..bdcd0dc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,36 +1,29 @@ +Thumbs.db +.DS_Store .gradle -**/build/ -!src/**/build/ bin - -# Ignore Gradle GUI config -gradle-app.setting - -# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) -!gradle-wrapper.jar - -# Avoid ignore Gradle wrappper properties -!gradle-wrapper.properties - -# Cache of project -.gradletasknamecache - -# Eclipse Gradle plugin generated files -# Eclipse Core -.project -# JDT-specific (Eclipse Java Development Tools) -.classpath -Thum -bs.db -.DS_Store +build/ +jte-classes +target/ out/ + +.lighthouseci .micronaut/ +.vagrant + .idea *.iml *.ipr *.iws + +.project .settings +.classpath .factorypath -jte-classes +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Avoid ignore Gradle wrappper properties +!gradle-wrapper.properties \ No newline at end of file diff --git a/README.md b/README.md index 65fce89..a98393b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ + + # Project Starter ![CI Workflow](https://github.com/Liber-UFPE/project-starter/actions/workflows/build.yml/badge.svg?branch=main) @@ -5,7 +7,7 @@ This is a project starter template. There are a few things you need to do after creating your repository using this template: -- [ ] Replace `project-starter`/`PROJECT_STARTER` (and other mentions) with your project's name +- [ ] Replace `project-starter`, `PROJECT_STARTER` (and other mentions) with your project's name - [ ] Edit `src/main/resources/public/stylesheets/main.css` as needed (different colors, fonts, etc.) - [ ] Edit `src/main/resources/public/javascript/main.js` as needed - [ ] Edit `src/main/jte/layout.kte` as necessary to support your project's navigation @@ -78,7 +80,7 @@ If you want to reload the application for every code change, run [Gradle in _con ## Requirements -1. Java 17+ (easier to install with [SDKMAN](https://sdkman.io/)) +1. Java 21 (easier to install with [SDKMAN](https://sdkman.io/)) 2. [Docker Desktop](https://www.docker.com/products/docker-desktop/) (if you want to test docker images) 3. [Ktlint CLI](https://pinterest.github.io/ktlint/1.0.0/install/cli/) (if you want to run code inspections locally) 4. [Gradle](https://gradle.org/install/#with-a-package-manager) (if you don't want to use the `./gradlew` script) @@ -100,6 +102,7 @@ The project is developed using Micronaut Framework, [Gradle](https://gradle.org/ It uses JTE/KTE as the template engine. - [JTE Website](https://jte.gg/) +- [Micronaut JTE Views documentation](https://micronaut-projects.github.io/micronaut-views/latest/guide/#jte) ### CI & CD @@ -111,7 +114,7 @@ We use [Kotest](https://kotest.io/) as the test framework, and [Kover](https://g ### Code Inspections -For every merge/push, and also for pull requests, there are GitHub Actions to run [ktlint](https://github.com/pinterest/ktlint) and [detekt](https://github.com/detekt/detekt). There is also an (experimental) integration with [DeepSource](https://deepsource.com/). +For every merge/push, and also for pull requests, there are GitHub Actions to run [ktlint](https://github.com/pinterest/ktlint) and [detekt](https://github.com/detekt/detekt). There is also an (experimental) integration with [DeepSource](https://deepsource.com/). Ktlint is configured to use `intellij_idea` code style so that it won't conflict with code formatting action in IDEA. @@ -130,3 +133,34 @@ Project follow the default [Maven Standard Directory Layout](https://maven.apach | `src/accessibilityTest` | Root folder for accessibility test code | | `.github` | Root folder for GitHub configurations | | `.github/workflows` | GitHub Actions configuration | + +## Micronaut 4.2.0 Documentation + +- [User Guide](https://docs.micronaut.io/4.2.0/guide/index.html) +- [API Reference](https://docs.micronaut.io/4.2.0/api/index.html) +- [Configuration Reference](https://docs.micronaut.io/4.2.0/guide/configurationreference.html) +- [Micronaut Guides](https://guides.micronaut.io/index.html) + +--- + +- [Shadow Gradle Plugin](https://plugins.gradle.org/plugin/com.github.johnrengelman.shadow) +- [Micronaut Gradle Plugin documentation](https://micronaut-projects.github.io/micronaut-gradle-plugin/latest/) +- [GraalVM Gradle Plugin documentation](https://graalvm.github.io/native-build-tools/latest/gradle-plugin.html) + +## Feature serialization-jackson documentation + +- [Micronaut Serialization Jackson Core documentation](https://micronaut-projects.github.io/micronaut-serialization/latest/guide/) + +## Feature ksp documentation + +- [Micronaut Kotlin Symbol Processing (KSP) documentation](https://docs.micronaut.io/latest/guide/#kotlin) +- [https://kotlinlang.org/docs/ksp-overview.html](https://kotlinlang.org/docs/ksp-overview.html) + +## Feature kotest documentation + +- [Micronaut Test Kotest5 documentation](https://micronaut-projects.github.io/micronaut-test/latest/guide/#kotest5) +- [https://kotest.io/](https://kotest.io/) + +## Feature micronaut-aot documentation + +- [Micronaut AOT documentation](https://micronaut-projects.github.io/micronaut-aot/latest/guide/) diff --git a/build.gradle.kts b/build.gradle.kts index 6c22afb..8f2f3bc 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,7 @@ import com.adarshr.gradle.testlogger.theme.ThemeType import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage +import io.github.vacxe.buildtimetracker.reporters.markdown.MarkdownConfiguration +import java.time.Duration import java.time.ZonedDateTime import java.time.format.DateTimeFormatter import java.time.format.FormatStyle @@ -8,12 +10,14 @@ import java.util.Locale plugins { id("org.jetbrains.kotlin.jvm") version "1.9.20" id("org.jetbrains.kotlin.plugin.allopen") version "1.9.20" - // If the project needs to add Serialization (to JSON, for example) - // id("org.jetbrains.kotlin.plugin.serialization") version "1.9.20" id("com.google.devtools.ksp") version "1.9.20-1.0.14" id("com.github.johnrengelman.shadow") version "8.1.1" id("io.micronaut.application") version "4.2.0" id("gg.jte.gradle") version "3.1.5" + id("io.micronaut.aot") version "4.2.0" + // Apply GraalVM Native Image plugin. Micronaut already adds it, but + // adding it explicitly allows to control which version is used. + id("org.graalvm.buildtools.native") version "0.9.28" // Provides better test output id("com.adarshr.test-logger") version "4.0.0" // Code Coverage: @@ -21,17 +25,25 @@ plugins { id("org.jetbrains.kotlinx.kover") version "0.7.4" // Code Inspections // https://detekt.dev/ - id("io.gitlab.arturbosch.detekt") version ("1.23.3") + id("io.gitlab.arturbosch.detekt") version "1.23.3" // Task graph utility // https://github.com/dorongold/gradle-task-tree id("com.dorongold.task-tree") version "2.1.1" - // To generate a git.properties file containing git repository metadata - id("com.gorylenko.gradle-git-properties") version "2.4.1" // Easily add new test sets + // https://github.com/unbroken-dome/gradle-testsets-plugin id("org.unbroken-dome.test-sets") version "4.1.0" + // Report task timings + // https://github.com/vacxe/build-time-tracker + id("io.github.vacxe.build-time-tracker") version "0.0.4" + // To check dependency updates + // https://github.com/ben-manes/gradle-versions-plugin + id("com.github.ben-manes.versions") version "0.50.0" } -val javaVersion: Int = 17 +val ci: Boolean = System.getenv().getOrDefault("CI", "false").toBoolean() +val releasing: Boolean = System.getenv().getOrDefault("RELEASING", "false").toBoolean() + +val javaVersion: Int = 21 val dockerImage: String = "ghcr.io/liber-ufpe/project-starter" val kotlinVersion: String = project.properties["kotlinVersion"] as String @@ -51,9 +63,6 @@ application { java { sourceCompatibility = JavaVersion.toVersion(javaVersion) - toolchain { - languageVersion = JavaLanguageVersion.of(javaVersion) - } } tasks.named("test", Test::class) { @@ -77,15 +86,26 @@ tasks.withType { ) } +// See https://graalvm.github.io/native-build-tools/latest/gradle-plugin.html graalvmNative { toolchainDetection.set(false) binaries { named("main") { + fallback.set(false) + richOutput.set(true) buildArgs.add("--verbose") - // 7GB is what is available when using Github-hosted runners: - // https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources - buildArgs.add("-J-Xmx7G") - buildArgs.add("--initialize-at-build-time=kotlin.coroutines.intrinsics.CoroutineSingletons") + if (ci) { + // A little extra verbose on CI to prevent jobs being killed + // due to the lack of output (since native-image creation can + // take a long time to complete). + jvmArgs.add("-Xlog:gc*") + } + + // Do a quick/un-optimized build. The intention is to validate + // it is possible to create a native-image. But, if it is running + // a `release` job, then it must create an optimized image, hence + // quickBuild must be false. + quickBuild.set(ci && !releasing) } } } @@ -95,27 +115,38 @@ micronaut { testRuntime("kotest5") processing { incremental(true) - annotations("br.ufpe.*") + annotations("br.ufpe.liber.*") + } + aot { + // Please review carefully the optimizations enabled below + // Check https://micronaut-projects.github.io/micronaut-aot/latest/guide/ for more details + optimizeServiceLoading.set(false) + convertYamlToJava.set(false) + precomputeOperations.set(true) + cacheEnvironment.set(true) + optimizeClassLoading.set(true) + deduceEnvironment.set(true) + optimizeNetty.set(true) } } jte { - sourceDirectory = layout.projectDirectory.dir("src/main/jte").asFile.toPath() - targetDirectory = layout.buildDirectory.dir("jte-classes").get().asFile.toPath() - trimControlStructures = true - packageName = "br.ufpe.liber" + sourceDirectory.set(file("src/main/jte").toPath()) + targetDirectory.set(layout.buildDirectory.dir("jte-classes").get().asFile.toPath()) + trimControlStructures.set(true) + packageName.set(project.group.toString()) generate() + jteExtension("gg.jte.nativeimage.NativeResourcesExtension") jteExtension("gg.jte.models.generator.ModelExtension") { property("language", "Kotlin") } } - +// Gradle requires that generateJte is run before some tasks tasks.configureEach { - if (listOf("kspKotlin", "inspectRuntimeClasspath").contains(name)) { + if (name == "inspectRuntimeClasspath" || name == "kspKotlin") { mustRunAfter("generateJte") } } - tasks.named("jar", Jar::class) { dependsOn.add("precompileJte") from(fileTree(layout.buildDirectory.file("jte-classes").get().asFile.absolutePath)) { @@ -129,6 +160,19 @@ testlogger { showStackTraces = true } +buildTimeTracker { + markdownConfiguration.set( + MarkdownConfiguration( + reportFile = project.reporting.file("build-times.md").absolutePath, + minDuration = Duration.ofMillis(0), + withTableLabels = true, + sorted = true, + take = Int.MAX_VALUE, + ) + ) +} + +// Outputs releaseDate in the format `2023 Nov 24 15:20:28`. tasks.register("releaseDate") { doLast { println( @@ -137,46 +181,36 @@ tasks.register("releaseDate") { .format( DateTimeFormatter .ofLocalizedDateTime(FormatStyle.MEDIUM) - .withLocale(Locale("pt-BR")), - ), + .withLocale(Locale.Builder().setLanguage("pt-BR").build()) + ) ) } } +// Install pre-commit git hooks to run ktlint and detekt +tasks.register("installGitHooks", Copy::class) { + from(layout.projectDirectory.file("scripts/pre-commit")) + into(layout.projectDirectory.dir(".git/hooks")) + fileMode = 755 +} + dependencies { + ksp("io.micronaut:micronaut-http-validation") ksp("io.micronaut.serde:micronaut-serde-processor") - implementation("io.micronaut:micronaut-aop") - implementation("io.micronaut:micronaut-http-client") - implementation("io.micronaut.serde:micronaut-serde-jackson") - implementation("io.micronaut.kotlin:micronaut-kotlin-runtime") implementation("io.micronaut.kotlin:micronaut-kotlin-extension-functions") - - compileOnly("org.graalvm.nativeimage:svm") + implementation("io.micronaut.kotlin:micronaut-kotlin-runtime") + implementation("io.micronaut.serde:micronaut-serde-jackson") + implementation("io.micronaut.views:micronaut-views-jte") + implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion") + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion") + compileOnly("io.micronaut:micronaut-http-client") runtimeOnly("ch.qos.logback:logback-classic") runtimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin") + testImplementation("io.micronaut:micronaut-http-client") - // Views Dependencies - implementation("gg.jte:jte-kotlin:$jteVersion") - implementation("gg.jte:jte-runtime:$jteVersion") - implementation("io.micronaut.views:micronaut-views-jte") + // jte dependencies jteGenerate("gg.jte:jte-models:$jteVersion") jteGenerate("gg.jte:jte-native-resources:$jteVersion") - - implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion") - implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion") - - // If the project needs to add Serialization (to JSON, for example). Also check the - // plugins section. - // implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0") - - // Netty security overrides - implementation("io.netty:netty-handler:4.1.101.Final") - implementation("io.netty:netty-codec-http2:4.1.101.Final") - - // Accessibility Tests - accessibilityTestImplementation("org.seleniumhq.selenium:selenium-java:4.15.0") - accessibilityTestImplementation("com.deque.html.axe-core:selenium:4.8.0") - - // Kotest manual update - testImplementation("io.micronaut.test:micronaut-test-kotest5:4.1.0") + implementation("gg.jte:jte:$jteVersion") + implementation("gg.jte:jte-kotlin:$jteVersion") } diff --git a/gradle.properties b/gradle.properties index 29d97a9..6d74954 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ -micronautVersion=4.1.1 -kotlinVersion=1.9.10 -jteVersion=3.1.3 +micronautVersion=4.2.0 +kotlinVersion=1.9.20 +jteVersion=3.1.5 # If it needs to add search # luceneVersion=9.8.0 diff --git a/gradlew b/gradlew index 0adc8e1..1aa94a4 100755 --- a/gradlew +++ b/gradlew @@ -145,7 +145,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -153,7 +153,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -202,11 +202,11 @@ fi # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/micronaut-cli.yml b/micronaut-cli.yml index c185e88..78c64fa 100644 --- a/micronaut-cli.yml +++ b/micronaut-cli.yml @@ -2,5 +2,5 @@ applicationType: default defaultPackage: br.ufpe.liber testFramework: kotest sourceLanguage: kotlin -buildTool: gradle -features: [app-name, config4k, github-workflow-ci, github-workflow-docker-registry, github-workflow-graal-docker-registry, graalvm, gradle, http-client, jib, kotest, kotlin, kotlin-application, ksp, logback, micronaut-aop, micronaut-aot, micronaut-build, netty-server, readme, serialization-jackson, shade, views-jte] +buildTool: gradle_kotlin +features: [app-name, config4k, graalvm, gradle, http-client-test, kotest, kotlin, kotlin-application, kotlin-extension-functions, ksp, logback, micronaut-aot, micronaut-build, micronaut-http-validation, netty-server, properties, readme, serialization-jackson, shade, views-jte] diff --git a/scripts/pre-commit b/scripts/pre-commit new file mode 100755 index 0000000..d2513ed --- /dev/null +++ b/scripts/pre-commit @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +GREEN=$(tput setaf 2) +BOLD=$(tput bold) +RESET=$(tput sgr0) + +function runKtlint { + echo -e "Running ${BOLD}${GREEN}ktlint${RESET} pre-commit hook on staged files" + git diff --name-only -z --cached --relative -- '*.kt' '*.kts' | ktlint --relative --patterns-from-stdin='' +} + +function runDetekt { + echo -e "Running ${BOLD}${GREEN}detekt${RESET} pre-commit hook on staged files" + changeset="$(git diff --name-only --cached --relative -- '*.kt' '*.kts' | paste -sd "," -)" + if [ -n "$changeset" ]; then + detekt --config detekt-config.yml \ + --build-upon-default-config\ + --input "$changeset" + else + echo "No Kotlin files to check!" + fi +} + +runKtlint +runDetekt + +STATUS=$? + +[ $STATUS -ne 0 ] && exit 1 + +exit 0 \ No newline at end of file diff --git a/src/main/kotlin/br/ufpe/liber/Application.kt b/src/main/kotlin/br/ufpe/liber/Application.kt index 838ccaf..5f06588 100644 --- a/src/main/kotlin/br/ufpe/liber/Application.kt +++ b/src/main/kotlin/br/ufpe/liber/Application.kt @@ -1,5 +1,3 @@ -@file:Suppress("FILE_NAME_MATCH_CLASS") - package br.ufpe.liber import gg.jte.ContentType diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index 87d79ac..824dc22 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -1,13 +1,14 @@ +#Fri Nov 24 17:16:53 UTC 2023 micronaut { - application { - name=project-starter - } + application { + name = project-starter + } - router { - static-resources { - default.enabled = true - default.mapping = "/public/**" - default.paths="classpath:public" - } + router { + static-resources { + default.enabled = true + default.mapping = "/public/**" + default.paths = "classpath:public" } + } } diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml index 44b79c4..2d77bda 100644 --- a/src/main/resources/logback.xml +++ b/src/main/resources/logback.xml @@ -4,7 +4,7 @@ - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + %cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n