Skip to content

Add RelocatingClassLoader to fix custom ruleset JARs#799

Merged
paul-dingemans merged 8 commits intonbadal:mainfrom
haysmike:fix-custom-rulesets
Feb 4, 2026
Merged

Add RelocatingClassLoader to fix custom ruleset JARs#799
paul-dingemans merged 8 commits intonbadal:mainfrom
haysmike:fix-custom-rulesets

Conversation

@haysmike
Copy link
Copy Markdown
Contributor

@haysmike haysmike commented Feb 1, 2026

Fixes #786

Description

9de656b broke custom rulesets JARs because the plugin now relocates org.jetbrains.kotlin to shadow.org.jetbrains.kotlin.

This PR transforms custom ruleset bytecode at load time using IntelliJ's bundled ASM library, remapping package references to match the shadow-relocated packages.

Testing

  1. Built the plugin
    ./gradlew clean build
    ./create-ktlint-plugin-zip.sh
  2. Installed in Android Studio (using "Install Plugin from Disk...") and restarted IDE
  3. Double-checked configuration with Compose rules:
    image
  4. Verified that I don't get any error popups, and that I see expected lint warnings in my composables:
    image

Note to reviewer(s)

I'm not an expert with IntelliJ plugin development or Java internals, so please feel free to redirect me towards better approaches. Also let me know if there's a unit test you'd like to see here - I wasn't sure how to test this in a reasonable way.

Thanks for all your work on ktlint!

@haysmike haysmike force-pushed the fix-custom-rulesets branch from 9651c02 to cd120dc Compare February 1, 2026 20:06
@haysmike haysmike force-pushed the fix-custom-rulesets branch from 516c0f9 to 91306bd Compare February 1, 2026 20:27
@haysmike haysmike force-pushed the fix-custom-rulesets branch from 91306bd to 0f6fa1a Compare February 1, 2026 20:28
Copy link
Copy Markdown
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.

Thank you so much for this contribution. I couldn't wrap my head around it myzelf. The code is clear, although I would have less intermediate variables myself. There is no need to change that though.

@haysmike
Copy link
Copy Markdown
Contributor Author

haysmike commented Feb 3, 2026

@paul-dingemans thanks for the feedback! I think I've addressed all your comments.

less intermediate variables myself

I generally prefer that too. I did a pass and inlined everything that I could (I think).

Feel free to make any edits you like as well - I have the "Allow edits by maintainers" option on 🙂

@paul-dingemans
Copy link
Copy Markdown
Collaborator

I will release a beta version tomorrow. It would be great if you can validate that version once more. After that I can release the stable version. It can take up to business days before it is approved by Jetbrains.

@paul-dingemans paul-dingemans merged commit 9a87a9d into nbadal:main Feb 4, 2026
5 checks passed
@paul-dingemans
Copy link
Copy Markdown
Collaborator

Version 0.30.4.-0-beta-1 has been published

@haysmike
Copy link
Copy Markdown
Contributor Author

haysmike commented Feb 4, 2026

@paul-dingemans The beta build works great for me! 🚀 🚀 🚀 🚀

@paul-dingemans
Copy link
Copy Markdown
Collaborator

@paul-dingemans The beta build works great for me! 🚀 🚀 🚀 🚀

Thanks for confirmation,. Stable release is being published now. It might take up to two business days before it is approved by JetBrains.

Once more, thanks for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0.30.2 breaks all custom ruleset JARs

2 participants