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

Enable gradle worker api by default on detekt tasks #6913

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

BraisGabin
Copy link
Member

@BraisGabin BraisGabin commented Jan 26, 2024

Closes #6887
Closes #2957

To get the reasoning behind this change read the related issue.

@BraisGabin BraisGabin changed the title Enable gradle worker api Enable gradle worker api by default on detekt tasks Jan 26, 2024
@detekt-ci
Copy link
Collaborator

detekt-ci commented Jan 26, 2024

Warnings
⚠️ It looks like this PR contains functional changes without a corresponding test.
⚠️

It looks like you're editing the un-versioned copy of our website. This affects only users on the 'next' version of detekt, and it's correct only if you intend to document a future change or feature. If you intended to make a change also for the current version of detekt, please make sure you edit the equivalent file inside website/versioned_docs/ as well.

Messages
📖

Thank you very much for making our website better ❤️!

Generated by 🚫 dangerJS against 83bcd45

Copy link

codecov bot commented Jan 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.79%. Comparing base (e78a5e1) to head (83bcd45).
Report is 31 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #6913   +/-   ##
=========================================
  Coverage     83.79%   83.79%           
  Complexity     3941     3941           
=========================================
  Files           579      579           
  Lines         12119    12119           
  Branches       2511     2511           
=========================================
  Hits          10155    10155           
  Misses          710      710           
  Partials       1254     1254           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@3flex 3flex left a comment

Choose a reason for hiding this comment

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

Maybe hold off, see #6964 and gradle/gradle#28034

@3flex
Copy link
Member

3flex commented Feb 25, 2024

Do you want to update the report merge docs to say that the worker API should be disabled if using the report merge feature? Then we can merge.

@BraisGabin
Copy link
Member Author

BraisGabin commented Mar 1, 2024

I was checking thy this failed on jdk11 and jdk8. And I found this: https://ge.detekt.dev/s/6lrnem2j7n3qs/tests/overview?outcome=FAILED

Two tests failed because of, I assume, gradle/gradle#28034. So it seems that gradle/gradle#28034 is related with the JDK version.

And the other one seems that we don't support the worker API on old versions of gradle. Regarding these we have two options: increase or minimum supported version of gradle to 7.6 or fix the problem and support worker API on 6.8.3.

@BraisGabin
Copy link
Member Author

I need to find a way to disable Worker API for the merge tests otherwise they are not going to pass.

internal const val USE_WORKER_API = "detekt.use.worker.api"

internal fun ProviderFactory.isWorkerApiEnabled(): Boolean {
val defaultValue = isGradleVersionAtLeast(major = 7, minor = 6).toString()
Copy link
Member Author

Choose a reason for hiding this comment

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

Gradle worker API doesn't work on any version below 7.6 so we don't enable it by default for those versions.

Copy link
Member

Choose a reason for hiding this comment

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

What changed in 7.6? Or did you discover that through testing? There's nothing in the 7.6 release notes about workers: https://docs.gradle.org/7.6/release-notes.html

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I was testing and 7.6 was the first one that work. No idea why it doesn't work on prior versions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably we should look at this and fix it. But I think that is a different issue.

Copy link
Member

@3flex 3flex Mar 11, 2024

Choose a reason for hiding this comment

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

I'm 99% sure this is an issue with our test setup and not a problem with this PR. Gradle is passing a Gradle plugin variant that's compatible with Gradle 8.2+ which fails in some scenarios on this earlier Gradle version. I ran into this in #7025 and #6489.

I'll open a new PR to address it, then I'm confident you can remove this check and rebase.

Copy link
Member

Choose a reason for hiding this comment

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

Should be fixed by #7036. I've also rebased #6489 on top of #7036 to prove that it works (functional tests used to fail because of a similar issue).

Copy link
Member Author

Choose a reason for hiding this comment

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

This code was removed, now Worker API is always enabled by default.

Copy link
Member

@3flex 3flex Mar 14, 2024

Choose a reason for hiding this comment

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

You might need to restore this check.

To isolate the issue I tried using 1.23.5 in a standalone Gradle project running 6.8.3. That failed. The earliest version that worked for me is 7.5, though in tests it only works if version is 7.6. So there's an existing issue unrelated to the Gradle version test split, and not directly related to this PR, and also some inconsistency in TestKit test vs running in a separate build.

I think enabling where possible with this check restored makes sense but it's odd that it's not working on older versions. The whole point of the process isolation mode is that the worker's classpath is isolated from Gradle's, so the Gradle version shouldn't matter here.

Copy link
Member Author

Choose a reason for hiding this comment

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

I must say that I'm a bit lost on this regard. I don't fully understand all the picture so it's difficult to me to know what's going on.

I'm going to restore it using 7.5 as the minimum version then :)

@BraisGabin BraisGabin marked this pull request as ready for review March 8, 2024 11:52
@BraisGabin BraisGabin requested a review from 3flex March 8, 2024 11:52
@3flex
Copy link
Member

3flex commented Mar 12, 2024

Annoying the build is still failing. I saw this in the log:

    w: Runtime JAR files in the classpath should have the same version. These files were found in the classpath:
        /home/runner/.gradle/wrapper/dists/gradle-6.8.3-bin/7ykxq50lst7lb7wx1nijpicxn/gradle-6.8.3/lib/kotlin-stdlib-1.4.20.jar (version 1.4)
        /home/runner/.gradle/wrapper/dists/gradle-6.8.3-bin/7ykxq50lst7lb7wx1nijpicxn/gradle-6.8.3/lib/kotlin-stdlib-common-1.4.20.jar (version 1.4)
        /home/runner/.gradle/wrapper/dists/gradle-6.8.3-bin/7ykxq50lst7lb7wx1nijpicxn/gradle-6.8.3/lib/kotlin-stdlib-jdk7-1.4.20.jar (version 1.4)
        /home/runner/.gradle/wrapper/dists/gradle-6.8.3-bin/7ykxq50lst7lb7wx1nijpicxn/gradle-6.8.3/lib/kotlin-stdlib-jdk8-1.4.20.jar (version 1.4)
        /home/runner/.gradle/wrapper/dists/gradle-6.8.3-bin/7ykxq50lst7lb7wx1nijpicxn/gradle-6.8.3/lib/kotlin-reflect-1.4.20.jar (version 1.4)
        /home/runner/work/detekt/detekt/detekt-gradle-plugin/build/tmp/functionalTestMinSupportedGradle/work/.gradle-test-kit/caches/jars-8/06130c2f1c60b901150c43a397642dca/kotlin-stdlib-1.9.20.jar (version 1.9)
        /home/runner/work/detekt/detekt/detekt-gradle-plugin/build/tmp/functionalTestMinSupportedGradle/work/.gradle-test-kit/caches/jars-8/a369b37b4f997a63d005d4a5f51fd41f/kotlin-reflect-1.9.20.jar (version 1.9)

So my fix is incomplete but it's strange that this is only occurring in this PR and not on main. I'll look into it.

@3flex
Copy link
Member

3flex commented Mar 16, 2024

I think I've had a fundamental misunderstanding of what process isolation actually achieves when using workers. The worker still has Gradle runtime in its classpath, which is why there's different behaviour when running with different Gradle versions. In many cases things work, because the Kotlin version on the Gradle classpath doesn't conflict with detekt's, but in other cases there's an issue because of Kotlin runtime behaviour changes and Gradle 6.8 embeds Kotlin 1.4.20.

Worker classloader isolation makes it possible to run tasks with different libraries to the buildscript classpath. Process isolation extends this to allow running tasks with different JDK or system properties to those used for Gradle itself.

Neither of these quite describes what we need to execute detekt.

TL;DR: The current worker implementation includes Gradle's runtime which conflicts with detekt's runtime. The worker implementation needs to change before we can use it.

Copy link
Member

@3flex 3flex left a comment

Choose a reason for hiding this comment

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

I'd unfortunately consider this blocked until gradle/gradle#28478 is fixed in Gradle.

@BraisGabin
Copy link
Member Author

After #7060 I'll benchmark these again to see how it behaves.

@BraisGabin
Copy link
Member Author

I move to draft this again, I need to perform benchmarks again (Note for myself)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked documentation gradle-plugin notable changes Marker for notable changes in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable Gradle Worker API by default Changing any core class invalidates cached detekt classloader
4 participants