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

--reporter/--ruleset Java 9+ compatibility #259

Closed
josephmbeveridge opened this issue Jul 27, 2018 · 3 comments · Fixed by #577
Closed

--reporter/--ruleset Java 9+ compatibility #259

josephmbeveridge opened this issue Jul 27, 2018 · 3 comments · Fixed by #577

Comments

@josephmbeveridge
Copy link

josephmbeveridge commented Jul 27, 2018

I checked out the repo and ran ./gradlew build in ktlint-ruleset-template to generate the jars. I then tried running ktlint with all of those jars against a kotlin class and received

Exception in thread "main" java.lang.ClassCastException: java.base/jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to java.base/java.net.URLClassLoader
	at com.github.shyiko.ktlint.Main.loadJARs(Main.kt:567)
	at com.github.shyiko.ktlint.Main.main(Main.kt:253)

I can't see anything wrong with the jar structure or the paths I am using, but I'm guessing I have done something wrong.

The command I used was:
ktlint -R build/libs/ktlint-ruleset-template.jar src/main/kotlin/yourpkgname/NoVarRule.kt

I also tried using the sources jar.

@josephmbeveridge
Copy link
Author

I've confirmed that my ktlint is up to date and running it without the jar against the class in question does work.

@shyiko
Copy link
Collaborator

shyiko commented Jul 27, 2018

You must be running Java 9+.
https://github.com/shyiko/ktlint/blob/84d8931828311bd1bbcc7521b6524ef906d3135b/ktlint/src/main/kotlin/com/github/shyiko/ktlint/Main.kt#L642-L644
The fix is relatively simple: we need to use a separate class loader instead of hijacking SystemClassLoader.
If you have the time for a PR - I can promise a release within 24h of "Merge".

@josephmbeveridge
Copy link
Author

Thanks for the quick response.

You're right, it looks like I am on Java 9. I'll see if I have time to look into fixing this.

@shyiko shyiko changed the title Template custom rule steps don't appear to work --reporter/--ruleset Java 9+ compatibility Aug 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants