macisamuele / language-formatters-pre-commit-hooks

Collection of custom pre-commit hooks.
Apache License 2.0
115 stars 58 forks source link

How can I pass "java arguments" to the hook? #139

Closed ReXtrem closed 1 year ago

ReXtrem commented 1 year ago

.pre-commit-config.yaml:

default_language_version:
  python: python3

repos:
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks.git
  rev: v2.4.0
  hooks:
  - id: pretty-format-java
    args: [--autofix]
  - id: pretty-format-yaml
    args: [--autofix, --indent, '2']

Because of OpenJDK 16 feature: https://openjdk.org/jeps/396

I get the following error:

Run command: ('java', '--add-exports', 'jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED', '--add-exports', 'jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED', '--add-exports', 'jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED', '--add-exports', 'jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED', '--add-exports', 'jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED', '-jar', 'C:\\Users\\user\\.cache\\pre-commit\\google-java-formatter1.15.0.jar', 

And the solution would be to either add the following argument to the java command:

java --illegal-access=permit

Or this list of parameters:

--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED

How can I do it in this pre-commit hook?

macisamuele commented 1 year ago

@NoFuchsGavin In cd89b2aca36d32eec0d83cd938e4e737e93e785e / v2.5.0 we added the list of exports that were needed to allow running the formatter with JDK16+. I would suggest to update the version first and if the problem persist please re-open the issue (please not that PRs are welcome)