diff --git a/.editorconfig b/.editorconfig index 01626914c0..ffa28b6ae7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -37,3 +37,6 @@ max_line_length = unset [gradle/verification-metadata.xml] indent_size = 3 + +[*.yml] +ij_yaml_spaces_within_brackets = false diff --git a/.github/actions/setup-gradle-build/action.yml b/.github/actions/setup-gradle-build/action.yml new file mode 100644 index 0000000000..6febb231c7 --- /dev/null +++ b/.github/actions/setup-gradle-build/action.yml @@ -0,0 +1,40 @@ +name: Setup Gradle +description: Sets up the environment to run Gradle + +inputs: + gradle-jvm-args: + description: "JVM args to pass to Gradle" + required: true + # Github-Hosted nodes have only 7GB of RAM available. Looking at build scans Gradle process requires slightly more than 0.5GB. + # Keeping this setting low, allows other, forked JVM processes (like tests) to use remaining memory. + # Increase this value, only if GC time visible in build scans will take more than a few seconds. + default: "-Xmx1g" + additional-java-versions: + description: "Java versions installed on the side of the default Java version required by the build" + required: false + +runs: + using: composite + + steps: + - uses: actions/setup-java@v3 + with: + distribution: 'zulu' + java-version: | # last version (set as default) should match all `jvmToolchain(xxx)` calls in the project + ${{ inputs.additional-java-versions }} + 20 + + # Please note these settings will override the ones set via `gradle.properties` committed to the repository - https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties + # List of optimizations: + # - `jvm-args` fine-tuned to the CI runner & tasks being invoked + # - disabled File System Watching to improve Windows build times. CI runs don't modify source files, hence they don't need to pay extra cost to efficiently track changed files. + - name: Optimize Gradle build properties for CI + run: | + mkdir -p ~/.gradle + printf "org.gradle.jvmargs=${{ inputs.gradle-jvm-args }}\n" >> ~/.gradle/gradle.properties + printf "org.gradle.vfs.watch=false\n" >> ~/.gradle/gradle.properties + shell: bash + + - uses: gradle/gradle-build-action@v2 + with: + gradle-home-cache-cleanup: true diff --git a/.github/workflows/gradle-wrapper-validation.yml b/.github/workflows/gradle-wrapper-validation.yml index 9b0767d294..2b7cca24a3 100644 --- a/.github/workflows/gradle-wrapper-validation.yml +++ b/.github/workflows/gradle-wrapper-validation.yml @@ -1,6 +1,6 @@ name: "Validate Gradle Wrapper" -on: [ push, pull_request ] +on: [push, pull_request] jobs: validation: diff --git a/.github/workflows/publish-release-build.yml b/.github/workflows/publish-release-build.yml index 7ecfb50de2..82c6ac2bab 100644 --- a/.github/workflows/publish-release-build.yml +++ b/.github/workflows/publish-release-build.yml @@ -1,8 +1,8 @@ name: Publish release build -on : - push : - tags : +on: + push: + tags: - '*.*.*' jobs: @@ -14,26 +14,23 @@ jobs: - uses: actions/checkout@v3 with: ref: 'master' - - uses: actions/setup-java@v3 - with: - distribution: 'zulu' - java-version: 19 - - uses: gradle/gradle-build-action@v2 - with: - gradle-home-cache-cleanup: true + + + - uses: ./.github/actions/setup-gradle-build + - name: Build executable and publish to Maven run: ./gradlew clean shadowJarExecutable publishMavenPublicationToMavenCentralRepository --no-daemon --no-parallel --no-configuration-cache env: SONATYPE_NEXUS_USERNAME: ${{ secrets.SONATYPE_NEXUS_USERNAME }} SONATYPE_NEXUS_PASSWORD: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} - ORG_GRADLE_PROJECT_signingKey : ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEY }} + ORG_GRADLE_PROJECT_signingKey: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEY }} ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEYID }} - ORG_GRADLE_PROJECT_signingKeyPassword : ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGPASSWORD }} + ORG_GRADLE_PROJECT_signingKeyPassword: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGPASSWORD }} - - name : Extract release notes - id : release_notes + - name: Extract release notes + id: release_notes if: ${{ success() }} - uses : ffurrer2/extract-release-notes@v1 + uses: ffurrer2/extract-release-notes@v1 - name: Get version id: get_version @@ -49,18 +46,18 @@ jobs: cp ktlint ktlint-${{ env.version }}/bin zip -rm ktlint-${{ env.version }}.zip ktlint-${{ env.version }} - - name : Create release + - name: Create release id: github_release if: ${{ success() }} - uses : softprops/action-gh-release@v1 - with : + uses: softprops/action-gh-release@v1 + with: draft: false prerelease: false - body : ${{ steps.release_notes.outputs.release_notes }} + body: ${{ steps.release_notes.outputs.release_notes }} files: | ktlint-cli/build/run/* - env : - GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Bump Homebrew Formula if: ${{ success() }} diff --git a/.github/workflows/publish-snapshot-build.yml b/.github/workflows/publish-snapshot-build.yml index 59c9add0d3..6c6cb80ae2 100644 --- a/.github/workflows/publish-snapshot-build.yml +++ b/.github/workflows/publish-snapshot-build.yml @@ -2,7 +2,7 @@ name: Publish snapshot build on: push: - branches: [ master ] + branches: [master] paths: ['**/*.kt', '**/*.kts', '**/*.properties', '**/*.toml'] env: @@ -15,14 +15,11 @@ jobs: if: github.repository == 'pinterest/ktlint' steps: - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 - with: - distribution: 'zulu' - java-version: 19 - - uses: gradle/gradle-build-action@v2 - with: - gradle-home-cache-cleanup: true + + - uses: ./.github/actions/setup-gradle-build + - name: Publish snapshot to Maven run: ./gradlew clean publishMavenPublicationToMavenCentralRepository --no-daemon --no-parallel --no-configuration-cache + - name: Publish Kotlin-dev snapshot to Maven run: ./gradlew -PkotlinDev clean publishMavenPublicationToMavenCentralRepository --no-daemon --no-parallel --no-configuration-cache diff --git a/.github/workflows/pull-request-with-code.yml b/.github/workflows/pull-request-with-code.yml index 9dcc8293de..7a8be89c8d 100644 --- a/.github/workflows/pull-request-with-code.yml +++ b/.github/workflows/pull-request-with-code.yml @@ -17,38 +17,31 @@ on: - '**/*.toml' workflow_dispatch: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + env: - ORG_GRADLE_PROJECT_signingKey : ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEY }} + ORG_GRADLE_PROJECT_signingKey: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEY }} ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGKEYID }} - ORG_GRADLE_PROJECT_signingKeyPassword : ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGPASSWORD }} + ORG_GRADLE_PROJECT_signingKeyPassword: ${{ secrets.ORG_GRADLE_PROJECT_SIGNINGPASSWORD }} CLI_TEST_MAX_DURATION_IN_SECONDS: 10 -# Note that "jobs.build.strategy" and "jobs.build.runs-on" should be kept in sync with "pull-request-wth-code" +# Note that all "jobs" (build, tests) including "jobs.*.runs-on" should be kept in sync with "pull-request-without-code" jobs: build: strategy: matrix: - os: [ ubuntu-latest, windows-latest ] - # When changing the list of JDK versions, the build configuration has to be changed by a repository admin. See - # https://github.com/pinterest/ktlint/pull/1787#issuecomment-1409074092 - jdk: [ 8, 11, 17, 19 ] - exclude: # windows with JDK8 are *really* flaky - - os: windows-latest - jdk: 8 + os: [ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} + name: "[build] OS=${{ matrix.os }} Kotlin=stable" steps: - uses: actions/checkout@v3 - - uses: actions/setup-java@v3 - with: - distribution: 'zulu' - java-version: ${{ matrix.jdk }} - - uses: gradle/gradle-build-action@v2 - with: - gradle-home-cache-cleanup: true + + - uses: ./.github/actions/setup-gradle-build + - name: Build with release Kotlin version - run: ./gradlew build ktlintCheck --no-configuration-cache - - name: Build with dev Kotlin version - run: ./gradlew -PkotlinDev build ktlintCheck --no-configuration-cache + run: ./gradlew ktlintCheck build - name: Check `data class`es are not part of public API run: | @@ -70,3 +63,34 @@ jobs: exit 1 fi shell: bash + + build-dev: + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + runs-on: ${{ matrix.os }} + name: "[build] OS=${{ matrix.os }}, Kotlin=dev" + steps: + - uses: actions/checkout@v3 + + - uses: ./.github/actions/setup-gradle-build + + - name: Build with assemble Kotlin version + run: ./gradlew -PkotlinDev ktlintCheck build + + tests: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + jdk: [8, 11, 17] # list of Java versions to run tests against (excluding `java-compilation` version for which tests already have run during `build` job) + runs-on: ${{ matrix.os }} + name: "[tests] OS=${{ matrix.os }}, Java=${{ matrix.jdk }}" + steps: + - uses: actions/checkout@v3 + + - uses: ./.github/actions/setup-gradle-build + with: + additional-java-versions: ${{ matrix.jdk }} + + - run: ./gradlew testOnJdk${{ matrix.jdk }} -PtestJdkVersion=${{ matrix.jdk }} diff --git a/.github/workflows/pull-request-without-code.yml b/.github/workflows/pull-request-without-code.yml index adb7caa688..926c463373 100644 --- a/.github/workflows/pull-request-without-code.yml +++ b/.github/workflows/pull-request-without-code.yml @@ -19,18 +19,32 @@ on: - '!**/*.toml' # Add a dummy job that return true so that a PR not containing any code can be merged to master -# Note that "jobs.build.strategy" and "jobs.build.runs-on" should be kept in sync with "pull-request-wth-code" +# Note that all "jobs" (build, tests) including "jobs.*.runs-on" should be kept in sync with "pull-request-with-code" jobs: build: strategy: matrix: - os: [ ubuntu-latest, windows-latest ] - # When changing the list of JDK versions, the build configuration has to be changed by a repository admin. See - # https://github.com/pinterest/ktlint/pull/1787#issuecomment-1409074092 - jdk: [ 8, 11, 17, 19 ] - exclude: # windows with JDK8 are *really* flaky - - os: windows-latest - jdk: 8 + os: [ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} + name: "[build] OS=${{ matrix.os }} Kotlin=stable" + steps: + - run: 'echo "No build required"' + + build-dev: + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + runs-on: ${{ matrix.os }} + name: "[build] OS=${{ matrix.os }}, Kotlin=dev" + steps: + - run: 'echo "No build required"' + + tests: + strategy: + matrix: + os: [ubuntu-latest, windows-latest] + jdk: [ 8, 11, 17 ] + runs-on: ${{ matrix.os }} + name: "[tests] OS=${{ matrix.os }}, Java=${{ matrix.jdk }}" steps: - run: 'echo "No build required"' diff --git a/CHANGELOG.md b/CHANGELOG.md index b6948386f4..ee2868f0ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). * Update dependency com.google.jimfs:jimfs to v1.3.0 ([#2112](https://github.com/pinterest/ktlint/pull/2112)) * As a part of public API stabilization, configure `binary-compatibility-validator` plugin for compile-time verification of binary compatibility with previous `ktlint` versions ([#2131](https://github.com/pinterest/ktlint/pull/2131)) * Update dependency org.junit.jupiter:junit-jupiter to v5.10.0 ([#2148](https://github.com/pinterest/ktlint/pull/2148)) +* Build the project with Java 20, run test on Java 8, 11, 17 and 20 ([#1888](https://github.com/pinterest/ktlint/issues/1888)) ## [0.50.0] - 2023-06-29 diff --git a/README.md b/README.md index 9e494db6fc..dcc23c2d6c 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@
-
+
diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts
index bffd7b7aff..f35ccc42ef 100644
--- a/build-logic/build.gradle.kts
+++ b/build-logic/build.gradle.kts
@@ -1,3 +1,6 @@
+import org.jetbrains.kotlin.gradle.dsl.JvmTarget
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
+
plugins {
`kotlin-dsl`
}
@@ -6,14 +9,30 @@ repositories {
mavenCentral()
}
+kotlin {
+ jvmToolchain(libs.versions.java.compilation.get().toInt())
+}
+
+// TODO: Remove setting `options.release` and `compilerOptions.jvmTarget` after upgrade to Kotlin Gradle Plugin 1.9
+// build-logic is an internal project and given we know how the "actual" project is built - it's fine to target current java here as well.
+// @see https://github.com/pinterest/ktlint/pull/2120#discussion_r1260229055 for more details
+val buildLogicTargetJavaVersion = JavaVersion.VERSION_17
+tasks.withType