admin管理员组文章数量:1123367
I want to use com.hubspot.maven.plugins:prettier-maven-plugin with maven project and integrate Prettier Java with Intellij. Below is the maven plugin configuration:
<plugin>
<groupId>com.hubspot.maven.plugins</groupId>
<artifactId>prettier-maven-plugin</artifactId>
<version>0.22</version>
<configuration>
<prettierJavaVersion>2.6.6</prettierJavaVersion>
<printWidth>110</printWidth>
<tabWidth>2</tabWidth>
<useTabs>false</useTabs>
<ignoreConfigFile>true</ignoreConfigFile>
<ignoreEditorConfig>true</ignoreEditorConfig>
</configuration>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>write</goal>
</goals>
</execution>
</executions>
</plugin>
Code formatting works well in the command line by calling "mvn prettier:write". The problem is integration with the Intellij. I want the code be formatted on every save of the file or by calling standard function Reformat code. All the examples I found on the Internet do not work for me. As far as I understood, to achieve the formatting on save, the plugin File Watcher should be used.
There are like two ways to achieve the formatting - either calling mvn or npx. npx should work faster as a maven, so it should be a preferred way, but looks like Java project should have package.json file with dependencies and .prettierrc.yml file. This does not sound like a very nice solution because I have a Java project, not a node...
However, despite which solution (with mvn or npx) I choose, File Watcher has troubles by recognising a Program. If I give only mvn or npx, it always complains, that the Program is not found, so the absolute path to mvn or npx should be provided:
- mvn -> ~/.sdkman/candidates/maven/current/bin/mvn
- npx -> ~/.nvm/versions/node/v20.11.1/bin/npx
But still, wenn a changes to the file are made and File Watcher is triggered, following errors occur:
- mvn -> /home/user/.sdkman/candidates/maven/current/bin/mvn prettier:write -Dprettier.inputGlobs=src/main/java/com/example/MyFile.java
[ERROR] No plugin found for prefix 'prettier' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/home/user/.m2/repository)
- npx -> ~/.nvm/versions/node/v20.11.1/bin/npx prettier --write /home/user/project/src/main/java/com/example/MyFile.java
/usr/bin/env: ‘node’: No such file or directory
If I call the same command in the path of the project in the command line directly, then everything works with both tools (mvn and npx).
Should I define some global variables, or is it bug in Intellij?
本文标签: Java Prettier with maven and IntellijStack Overflow
版权声明:本文标题:Java Prettier with maven and Intellij - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736565482a1944696.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论