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

Java format hook does not work on Java 1.8 #171

Closed
vitalca opened this issue Jun 8, 2023 · 4 comments
Closed

Java format hook does not work on Java 1.8 #171

vitalca opened this issue Jun 8, 2023 · 4 comments

Comments

@vitalca
Copy link

vitalca commented Jun 8, 2023

The --add-exports command line option was added in Java 9.
When running on Java 1.8, you don't need to add these exports. Java fails to start.

Unfortunately, a lot of enterprise legacy code still uses JDK 1.8, This version is going to be supported till the end of 2030.

As a workaround I've added an alias to my ~/.bashrc, and I run gitc instead of git commit:

alias gitc='PATH=~/.sdkman/candidates/java/17/bin:$PATH git commit'
@macisamuele
Copy link
Owner

macisamuele commented Jun 8, 2023

I'm not a bit Java expert and I'll try to document myself a bit more.
In the meantime on the link you have referenced there is no trace of 1.8 version.
Something worth mentioning is that recent versions of Google Java Formatter might not work without the add exports, which implies that you wouldn't be able to run them on your java version.

@vitalca
Copy link
Author

vitalca commented Jun 8, 2023

Hi Samuele,

In the meantime on the link you have referenced there is no trace of 1.8 version.

Java 1.8 == Java 8, so it is mentioned over there.

Please look at the code in the pretty_format_java.py.

According to the google-java-format/README, the --add-exports JVM flags are required when running on JDK 16 and newer.

What needs to be done is the following.

  1. check java version (there is a function for this)
  2. for any versions >= 16, you add the --add-exports arguments.
  3. for all versions below 16 you do not add them.

That's it. Thanks 🙂

@vitalca
Copy link
Author

vitalca commented Jun 9, 2023

Google Formatter does not start on JDK 8.
Sorry for bothering.

@vitalca vitalca closed this as not planned Won't fix, can't repro, duplicate, stale Jun 9, 2023
@macisamuele
Copy link
Owner

Thanks for the the report and carrying the check already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants