-
Notifications
You must be signed in to change notification settings - Fork 460
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
Remove reflection from KtLintStep test. #187
Conversation
Reflection makes it really hard to maintain and add new features. This makes the code much easier to read and maintain.
Spotless works with a ton of different formatting libraries (off the top of my head: eclipse, google-java-format, ktlint, scalafmt, greclipse, freshmark). For each formatting library, we're also compatible with many versions of it, so that users can upgrade or downgrade versions without relying on Spotless cutting a new release. For each formatter, we resolve a special classpath for just that lone formatter and its deps. The approach used in this PR would break quickly if you made the same changes for the other formatters - the transitive deps would clash, not to mention trying to add support for multiple versions. I agree the reflection is ugly and hard to maintain, but it's an overall win because it greatly reduces the amount of maintaining that needs to be done. |
Thanks for the explanation. What do you think of using a |
I'm kind of curious about this too. I wonder if the reason this approach hasn't been tried yet is because if two formatter libraries A and B depend on a library C, but the versions of C they import are incompatible with one another, then Gradle will automatically choose one version of C for both A and B to use, but then either A and B will fail or do their jobs incorrectly. Is my understanding correct @nedtwigg? Or is there something else or more to it than that? |
That's one of the issues. The compileOnly trick is a handy one for cases like this. Goomph, the plugin that makes
There are a quite a few gotchas though:
For any single FormatterStep, the pros of compileOnly outweigh the cons. For the project as a whole, I think the cons outweigh the pros. My recommendation is:
I'm open to exploring the compileOnly option, but I'll only have time to point out the problems with it, I don't have time to help fix them. Here are the requirements for switching to compileOnly:
If all of this was complete, but the final result was harder to maintain than the previous result, I would be hesitant to merge it. It seems likely that the extra magic and complexity in the build (which is already pretty complex) would outweigh the simplicity in the FormatterStep (which are already pretty simple). I'll try to keep an open mind, but I'm nervous because it would be so much work for whoever contributes it, but even so I'll be stuck keeping the build running and releasing for the next N years, so I'm pretty conservative about changes that will make that more tedious. |
Oh wow, I hadn't realised there was so much that could go wrong with a compileOnly solution. Thank you very much for the extensive explanation! |
Reflection makes it really hard to maintain and add new features.
This makes the code much easier to read and maintain.
Let me know if this is okay or not. I wasn't too clear on the reasoning on why it was this way before.