Skip to content
New issue

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

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

Already on GitHub? # 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

Conversation

mateuszkwiecinski
Copy link
Contributor

@mateuszkwiecinski mateuszkwiecinski commented Jul 9, 2023

Closes #1888

Description

I wanted to open the project, but it failed to sync for me locally (because my defaults point to Java 20), so I decided to make the build more deterministic. I'll comment out all changes in the PR since some of them require your input, but the tl;dr is:

  • The project will be built only with a single Java version (that's what the release workflow does)
  • Only tests will be invoked on various Java versions (that's what project consumers do)
  • The project will compile on Java 20, and if someone doesn't have Java 11 or 20 installed locally, Gradle will fetch missing ones
  • I also removed a few of annoying compiler and deprecation warnings

Checklist

Before submitting the PR, please check following (checks which are not relevant may be ignored):

  • Commit message are well written. In addition to a short title, the commit message also explain why a change is made.
  • At least one commit message contains a reference Closes #<xxx> or Fixes #<xxx> (replace<xxx> with issue number)
  • Tests are added
  • KtLint format has been applied on source code itself and violations are fixed
  • CHANGELOG.md is updated
  • PR description added

Documentation is updated. See difference between snapshot and release documentation

@mateuszkwiecinski mateuszkwiecinski changed the title Setup toolchains, compile project with Java 20 only, run test on various java versions Setup toolchains, compile project with Java 20 only, run test on various Java versions Jul 9, 2023
.editorconfig Show resolved Hide resolved
.github/workflows/publish-release-build.yml Outdated Show resolved Hide resolved
.github/workflows/pull-request-with-code.yml Show resolved Hide resolved
.github/workflows/pull-request-with-code.yml Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
build.gradle.kts Show resolved Hide resolved
settings.gradle.kts Show resolved Hide resolved
@mateuszkwiecinski mateuszkwiecinski marked this pull request as ready for review July 9, 2023 20:07
Copy link
Collaborator

@paul-dingemans paul-dingemans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks you so much for all explanatory comments on the changes. As I have little Gradle knowledge, I wouldn't have understand what was changed. Now at least, I have some more understanding.

My biggest concern with this change is that there are many locations where a java version is to be changed whenever a new Java version is release or whenever an LTS version is dropped. So all location should be clearly marked with something like Java version for compilation (e.g. latest release Java version) or Supported LTS versions of Java + latest non-LTS version if applicable.

.github/workflows/publish-release-build.yml Outdated Show resolved Hide resolved
.github/workflows/publish-snapshot-build.yml Outdated Show resolved Hide resolved
.github/workflows/pull-request-with-code.yml Show resolved Hide resolved
.github/workflows/pull-request-with-code.yml Outdated Show resolved Hide resolved
.github/workflows/pull-request-with-code.yml Outdated Show resolved Hide resolved
settings.gradle.kts Show resolved Hide resolved
Copy link
Contributor Author

@mateuszkwiecinski mateuszkwiecinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed another proposal, with less distributed config:

  • Java compilation settings are now driven by versions defined in .toml file
  • Tested Java versions are now defined only within workflow file
  • Java version hardcoded in workflow files still have to be kept in sync, so I added necessary comments reminding to update the value

@paul-dingemans Please let me know if this suits you any better, or if the complexity in the configuration is not worth having since source of truth for Java setup

.github/workflows/pull-request-with-code.yml Show resolved Hide resolved
.github/workflows/pull-request-with-code.yml Outdated Show resolved Hide resolved
build-logic/build.gradle.kts Show resolved Hide resolved
gradle/libs.versions.toml Outdated Show resolved Hide resolved
.github/workflows/pull-request-with-code.yml Outdated Show resolved Hide resolved
.github/workflows/pull-request-with-code.yml Outdated Show resolved Hide resolved
build-logic/build.gradle.kts Outdated Show resolved Hide resolved
Copy link
Collaborator

@paul-dingemans paul-dingemans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saw that I had some more pending review comments.

Copy link
Contributor Author

@mateuszkwiecinski mateuszkwiecinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welp, I couldn't create separate PR, targeting this one since this branch lives only in my forked repository :/
I pushed another set of commits, on top of old ones, but if you want to see the diff alone, it can be viewed here: mateuszkwiecinski#3 🤷

.github/actions/setup-gradle-build/action.yml Show resolved Hide resolved
.github/actions/setup-gradle-build/action.yml Show resolved Hide resolved
.github/actions/setup-gradle-build/action.yml Show resolved Hide resolved
.github/workflows/pull-request-with-code.yml Show resolved Hide resolved
.github/workflows/pull-request-with-code.yml Show resolved Hide resolved
build-logic/build.gradle.kts Show resolved Hide resolved
gradle/libs.versions.toml Show resolved Hide resolved
@paul-dingemans
Copy link
Collaborator

We have to wait till next week before @shashachu is back from holidays. I cannot change the configuration so that the remaining checks are run as well.

@paul-dingemans
Copy link
Collaborator

@mateuszkwiecinski I am not sure whether we are both waiting for the other to proceed. As far as I know, there are still some conversations which I have not resolved because they are not fixed, but I could be wrong.

@mateuszkwiecinski
Copy link
Contributor Author

Yes, sorry, I saw your comments and I still plan to address them as soon as I find some time. Both here and in the other PR I have opened.
If you wanted to speed things up, you should be able to push to the branch, if not, I should be able to take another round tomorrow or on Thursday :)

@paul-dingemans
Copy link
Collaborator

Yes, sorry, I saw your comments and I still plan to address them as soon as I find some time. Both here and in the other PR I have opened. If you wanted to speed things up, you should be able to push to the branch, if not, I should be able to take another round tomorrow or on Thursday :)

Sure, no problem. Just wanted to make sure that we are aligned.

@mateuszkwiecinski
Copy link
Contributor Author

Oookay, I think I addressed all remaining items now. Please let me know in case I missed something 👀

If you manage to merge the new CI pipeline, I'll monitor build scans for a week or two to see if there are any bottlenecks or low-hanging fruits to improve CI build times 👀

@paul-dingemans
Copy link
Collaborator

I have merged #2136 earlier today. As of that a merge conflict appead in this PR. I am not sure how to resolve. So please have a look.

If someone doesn't have required java installed Gradle will attempt to install one
The build needs less than 0.5GB of a java heap memory. There is no value in reserving more than half of available RAM just for the Gradle demon. It's better to keep Gradle daemon small  and leave the memory available to other forked processes (i.e. tests)
CI doesn't modify files, there is no value in putting extra effort in efficiently tracking changed files. From test runs VFS comes with noticable performance impact on Windows build
@shashachu
Copy link
Contributor

I think the checks have been updated properly now.

@paul-dingemans
Copy link
Collaborator

I think the checks have been updated properly now.

Looks like it. The build succeeded. I will merge.

@paul-dingemans paul-dingemans merged commit 760279e into pinterest:master Jul 31, 2023
paul-dingemans added a commit to oshai/ktlint that referenced this pull request Jul 31, 2023
…ous Java versions (pinterest#2120)

* Replace testing on java 19 with testing on java 20

Closes pinterest#1888

* Unify `yml` files formating

* Do NOT compile the project with various Java version, instead test agains various java verstions

https://jakewharton.com/build-on-latest-java-test-through-lowest-java/

* Add `-add-opens` jvmArg to prevent ignored warnings

* Migrate away deprecated `java.net.URL` constructor

* Setup toolchain resolver

If someone doesn't have required java installed Gradle will attempt to install one

* Extract common build setup + fix memory settings

The build needs less than 0.5GB of a java heap memory. There is no value in reserving more than half of available RAM just for the Gradle demon. It's better to keep Gradle daemon small  and leave the memory available to other forked processes (i.e. tests)

* Disable VFS on CI

CI doesn't modify files, there is no value in putting extra effort in efficiently tracking changed files. From test runs VFS comes with noticable performance impact on Windows build

* Update comment with extra clarification

* Disable automatic build scans publishing on local builds

* Update kotlin dev version

* Fix `-PkotlinDev` not running tests agains configured kotlin version

* Fix `-PkotlinDev` artifacts version

* Run `-PkotlinDev` build as a separate workflow job in parallel

Co-authored-by: paul-dingemans <paul-dingemans@users.noreply.github.com>
@mateuszkwiecinski mateuszkwiecinski deleted the set_toolchains branch July 31, 2023 17:20
paul-dingemans added a commit to oshai/ktlint that referenced this pull request Jul 31, 2023
…ous Java versions (pinterest#2120)

* Replace testing on java 19 with testing on java 20

Closes pinterest#1888

* Unify `yml` files formating

* Do NOT compile the project with various Java version, instead test agains various java verstions

https://jakewharton.com/build-on-latest-java-test-through-lowest-java/

* Add `-add-opens` jvmArg to prevent ignored warnings

* Migrate away deprecated `java.net.URL` constructor

* Setup toolchain resolver

If someone doesn't have required java installed Gradle will attempt to install one

* Extract common build setup + fix memory settings

The build needs less than 0.5GB of a java heap memory. There is no value in reserving more than half of available RAM just for the Gradle demon. It's better to keep Gradle daemon small  and leave the memory available to other forked processes (i.e. tests)

* Disable VFS on CI

CI doesn't modify files, there is no value in putting extra effort in efficiently tracking changed files. From test runs VFS comes with noticable performance impact on Windows build

* Update comment with extra clarification

* Disable automatic build scans publishing on local builds

* Update kotlin dev version

* Fix `-PkotlinDev` not running tests agains configured kotlin version

* Fix `-PkotlinDev` artifacts version

* Run `-PkotlinDev` build as a separate workflow job in parallel

Co-authored-by: paul-dingemans <paul-dingemans@users.noreply.github.com>
tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
val requestedJdkVersion = project.findProperty("testJdkVersion")?.toString()?.toInt()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@mateuszkwiecinski mateuszkwiecinski Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the value of doing extra abstraction if the property is consumed immediately, at the configuration time?

Lazy APIs are useful to take the burden off the single-threaded configuration phase and do more things during task execution time. The documentation: https://docs.gradle.org/current/userguide/lazy_configuration.html#lazy_properties doesn't mention our setup as an example use case that would benefit lazy configuration.
I'd still suggest using simpler version, as long as it's not deprecated, or adding extra complexity comes with any performance benefit 🤷

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the Gradle recommending way, I'd prefer to follow the best practice.

Copy link
Contributor Author

@mateuszkwiecinski mateuszkwiecinski Aug 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the Gradle recommending way

Can you link where Gradle recommends using providers in use cases like this? I agree it's a general recommendation to:

  1. wire Gradle models
  2. wiring Task inputs & outputs
  3. Avoiding doing work during configuration phase
    None of them are applicable here, and blindly using lazy APIs doesn't bring any value.

I can also link this: which says:

Avoid simplifying calls like obj.getProperty().get() and obj.getProperty().set(T) in your code by introducing additional getters and setters.

which is exactly what you'd have to do if you used gradleProperty() api 🤷

An alternative approach to using native Gradle APIs (like I did), is to use kts delegates, in this case:val testJdkVersion: String? by project, but that's a syntactic sugar and doesn't change behavior (in context of being lazy or not) 🤷

I'll be happy to be proven wrong, otherwise forcing to use lazy for properties that are consumed only during configuration phase is useless 🤷

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add testing on Java 20 and remove testing for Java 19
4 participants