Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup toolchains, compile project with Java 20 only, run test on various Java versions #2120

Merged
merged 24 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
88bde93
Replace testing on java 19 with testing on java 20
paul-dingemans Mar 25, 2023
c1a0e41
Fix toolchains. Compile project with Java 20, continue targeting Java…
mateuszkwiecinski Jul 9, 2023
7370ea0
Unify `yml` files formating
mateuszkwiecinski Jul 9, 2023
b03a4be
Fix compiler warning
mateuszkwiecinski Jul 9, 2023
dbff741
Do NOT compile the project with various Java version, instead test ag…
mateuszkwiecinski Jul 9, 2023
652aef7
Add `-add-opens` jvmArg to prevent ignored warnings
mateuszkwiecinski Jul 9, 2023
9bf8592
Fix readme badge
mateuszkwiecinski Jul 9, 2023
b4f6146
Migrate away deprecated `java.net.URL` constructor
mateuszkwiecinski Jul 9, 2023
bad36e7
Setup toolchain resolver
mateuszkwiecinski Jul 9, 2023
cf3464b
Improve CI performance
mateuszkwiecinski Jul 11, 2023
9313464
Update workflow name
mateuszkwiecinski Jul 11, 2023
12cdbf1
Move JDK compile/target version to `libs.versions.toml` file
mateuszkwiecinski Jul 15, 2023
711e6bf
Add more explanation comments
mateuszkwiecinski Jul 15, 2023
b9d6b7a
Rename `targetJavaVersion` -> `buildLogicTargetJavaVersion`
mateuszkwiecinski Jul 15, 2023
9de34cc
Pre-register all testOnJdk test tasks for all LTS java versions
mateuszkwiecinski Jul 15, 2023
b1823b4
Extract common build setup + fix memory settings
mateuszkwiecinski Jul 15, 2023
1931e09
Disable VFS on CI
mateuszkwiecinski Jul 15, 2023
18f069f
Update comment with extra clarification
mateuszkwiecinski Jul 15, 2023
455b383
Disable automatic build scans publishing on local builds
mateuszkwiecinski Jul 15, 2023
0ab55cc
Update kotlin dev version
mateuszkwiecinski Jul 16, 2023
a49c0d5
Fix `-PkotlinDev` not running tests agains configured kotlin version
mateuszkwiecinski Jul 16, 2023
3a0abff
Fix `-PkotlinDev` artifacts version
mateuszkwiecinski Jul 16, 2023
3ab1521
Run `-PkotlinDev` build as a separate workflow job in parallel
mateuszkwiecinski Jul 16, 2023
53bd98f
Add extra comment explaining CI runner settings
mateuszkwiecinski Jul 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ max_line_length = unset

[gradle/verification-metadata.xml]
indent_size = 3

[*.yml]
ij_yaml_spaces_within_brackets = false
paul-dingemans marked this conversation as resolved.
Show resolved Hide resolved
40 changes: 40 additions & 0 deletions .github/actions/setup-gradle-build/action.yml
Original file line number Diff line number Diff line change
@@ -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"
paul-dingemans marked this conversation as resolved.
Show resolved Hide resolved
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
paul-dingemans marked this conversation as resolved.
Show resolved Hide resolved

# 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
paul-dingemans marked this conversation as resolved.
Show resolved Hide resolved
printf "org.gradle.vfs.watch=false\n" >> ~/.gradle/gradle.properties
shell: bash

- uses: gradle/gradle-build-action@v2
with:
gradle-home-cache-cleanup: true
2 changes: 1 addition & 1 deletion .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "Validate Gradle Wrapper"

on: [ push, pull_request ]
on: [push, pull_request]

jobs:
validation:
Expand Down
39 changes: 18 additions & 21 deletions .github/workflows/publish-release-build.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Publish release build

on :
push :
tags :
on:
push:
tags:
- '*.*.*'

jobs:
Expand All @@ -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
Expand All @@ -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() }}
Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/publish-snapshot-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Publish snapshot build

on:
push:
branches: [ master ]
branches: [master]
paths: ['**/*.kt', '**/*.kts', '**/*.properties', '**/*.toml']

env:
Expand All @@ -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
64 changes: 44 additions & 20 deletions .github/workflows/pull-request-with-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,31 @@ on:
- '**/*.toml'
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}
paul-dingemans marked this conversation as resolved.
Show resolved Hide resolved

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
mateuszkwiecinski marked this conversation as resolved.
Show resolved Hide resolved
# 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"
paul-dingemans marked this conversation as resolved.
Show resolved Hide resolved
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: |
Expand All @@ -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
paul-dingemans marked this conversation as resolved.
Show resolved Hide resolved

tests:
strategy:
fail-fast: false
mateuszkwiecinski marked this conversation as resolved.
Show resolved Hide resolved
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 }}
30 changes: 22 additions & 8 deletions .github/workflows/pull-request-without-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
paul-dingemans marked this conversation as resolved.
Show resolved Hide resolved
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"'
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<p align="center">
<a href="https://kotlinlang.slack.com/messages/CKS3XG0LS"><img src="https://img.shields.io/badge/slack-@kotlinlang/ktlint-yellow.svg?logo=slack" alt="Join the chat at https://kotlinlang.slack.com"/></a>
<a href="https://github.com/pinterest/ktlint/actions/workflows/gradle-snapshot-build.yml"><img src="https://github.com/pinterest/ktlint/actions/workflows/gradle-snapshot-build.yml/badge.svg" alt="Build status"></a>
<a href="https://github.com/pinterest/ktlint/actions/workflows/publish-snapshot-build.yml"><img src="https://github.com/pinterest/ktlint/actions/workflows/publish-snapshot-build.yml/badge.svg" alt="Build status"></a>
paul-dingemans marked this conversation as resolved.
Show resolved Hide resolved
<a href="https://search.maven.org/artifact/com.pinterest/ktlint"><img src="https://img.shields.io/maven-central/v/com.pinterest/ktlint.svg" alt="Maven Central"></a>
<a href="https://jitpack.io/#pinterest/ktlint"><img src="https://jitpack.io/v/pinterest/ktlint.svg" alt="JitPack"></a>
<a href="https://formulae.brew.sh/formula/ktlint"><img src="https://img.shields.io/homebrew/v/ktlint.svg" alt="HomeBrew"></a>
Expand Down
23 changes: 21 additions & 2 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`kotlin-dsl`
}
Expand All @@ -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<JavaCompile>().configureEach {
options.release.set(buildLogicTargetJavaVersion.majorVersion.toInt())
}
tasks.withType<KotlinCompile>().configureEach {
// Convert Java version (e.g. "1.8" or "11") to Kotlin JvmTarget ("8" resp. "11")
compilerOptions.jvmTarget.set(JvmTarget.fromTarget(buildLogicTargetJavaVersion.toString()))
}

dependencies {
val kotlinPlugin =
if (providers.gradleProperty("kotlinDev").orNull.toBoolean()) {
if (hasProperty("kotlinDev")) {
paul-dingemans marked this conversation as resolved.
Show resolved Hide resolved
// Pass '-PkotlinDev' to command line to enable kotlin-in-development version
logger.warn("Enabling kotlin dev version!")
libs.kotlin.plugin.dev
} else {
libs.kotlin.plugin
libs.kotlin.plugin.asProvider()
paul-dingemans marked this conversation as resolved.
Show resolved Hide resolved
}
implementation(kotlinPlugin)
implementation(libs.dokka)
Expand Down
4 changes: 4 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ dependencyResolutionManagement {
}
}
}

plugins {
id("org.gradle.toolchains.foojay-resolver-convention") version "0.6.0"
paul-dingemans marked this conversation as resolved.
Show resolved Hide resolved
}
Loading