-
Notifications
You must be signed in to change notification settings - Fork 463
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
Suggest prettier plugins as appropriate #1416
Comments
Doing some more resarch and I'm only getting more confused. I verified the issue on another machine running windows 10. However, I downgraded spring boot to 2.7 and the jdk to version 11 to try to get it to work again. It did not work, and I still get the stacktrace. Is there any way to make prettier output debug information when called through spotless? I'm not quite understanding how the REST API calls work here. |
Another update, it now happens in my github actions as well, using java 17: https://github.com/etnoy/herder/actions/runs/3619288302/jobs/6100151257 |
same issue with me using maven, anyone know some workaround to bypass this bug? |
@etnoy Prettier fails to infer a parser for java files, since prettier-core does not come with java support. You need to add the java community plugin for this to prettier. Just using Try this: spotless {
ratchetFrom 'origin/master' // only format files which have changed since origin/main
format 'misc', {
target '**/.gitignore', '**/*.gradle', '**/*.md', '**/*.sh'
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
java {
// use java community plugin for prettier
prettier(['prettier': '2.8.1', 'prettier-plugin-java': '2.0.0'])
toggleOffOn()
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
formatAnnotations()
licenseHeaderFile "${project.rootDir}/license.template"
}
} |
I can't believe that the solution was so obvious after chasing this issue for hours. Thanks for the explanation! |
We should add a check along the lines of: } catch (Exception e) {
if (e.getMessage().contains(".java")) {
throw new Exception("Prettier needs the java plugin, e.g. prettier(['prettier': '2.8.1', 'prettier-plugin-java': '2.0.0'])", e)
}
} |
That's a good idea that would have saved me a lot of head-scratching. I was wondering if there is any way to specify the prettier-plugin-java without an explicit version number? |
We could think about something like I would definitely merge a PR that suggests plugins to users based on errors. A PR that expands the prettier DSL would need some kind of story about how it's going to stay up-to-date. |
EDIT by @nedtwigg: this was a bug report, has turned into an enhancement spec, you can skip to the bottom.
I'm asking here because I've worked on this for hours on hours and I can't seem to get anywhere.
I'm using prettier 2.8.0 with prettier-java-plugin 2.0.0 and spotless 6.12.0.
I'm trying to use gradle+spotless+prettier to format Java code. I'm using Java 17 as that's required by Spring Boot v3.
I can run prettier manually on each of my Java files. I can run prettier via vscode. Any pointers would be appreciated.
No matter what I do, I get the following:
It appears to work when I'm downgrading Java down to version 11. However, that means I can't use Spring Boot v3.
If I manually tell prettier to use the java parser for .java files, it just tells me it can't load the java parser.
build.gradle:
The text was updated successfully, but these errors were encountered: