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

How to factorize Java 17 extra command line in a Parent POM ? #540

Open
aperusset opened this issue Feb 8, 2023 · 3 comments
Open

How to factorize Java 17 extra command line in a Parent POM ? #540

aperusset opened this issue Feb 8, 2023 · 3 comments

Comments

@aperusset
Copy link

aperusset commented Feb 8, 2023

Hi there !

I currently configure ktlint with Maven Antrun Plugin as explained there : https://pinterest.github.io/ktlint/install/integrations/ (and it's working like a charm). During the migration of our micro-services to Java 17, I've added the additional JVM args to the Antrun Plugin configuration (as documented).

<jvmarg value="--add-opens"/>
<jvmarg value="java.base/java.lang=ALL-UNNAMED"/>

Your plugin is very interesting for me as it could simplify the linter configuration, but the solution you propose for Java 17 does not fit my need : I have/want to factorize everything related to plugins, in other words plugin management, in my parent POM.

So, is there a way to achieve that regarding Java 17 with your plugin ? If not, is it planned to add some configuration to your plugin to activate these Java 17 flags ? Because adding the .mvn/jvm.config file in all parent depending projects is not an option.

Thank you for you reply !

@freemanjp
Copy link
Member

Hi @aperusset, thanks for raising this issue.

You can apply the settings to all projects for a user by adding the arguments in the MAVEN_OPTS environment variable e.g.
add the following to your ~/.profile (if on Unix/Linux):

export MAVEN_OPTS="--add-opens java.base/java.lang=ALL-UNNAMED"

Or you can add it to your ~/.mavenrc file:

MAVEN_OPTS="--add-opens java.base/java.lang=ALL-UNNAMED"

See https://maven.apache.org/configure.html

The only way this Maven plugin could add these arguments would be to fork a new JVM instance, which would make the plugin slower and require a significant amount of code to support. Not having to fork the JVM is the main advantage of using this plugin over the Maven Antrun Plugin. If you'd like to contribute a PR to support an option for forking the JVM, I'd be happy to consider it.

@bullet-tooth
Copy link

@freemanjp Are there any chances that the plugin would work without additional arguments to the compiler on Java 17+?

@freemanjp
Copy link
Member

Unfortunately, ktlint needs --add-opens java.base/java.lang=ALL-UNNAMED to be set on Java 16+. This is the code the command line ktlint version uses to add it when invoked https://github.com/pinterest/ktlint/blob/708e440f2ccf03dd3e1b0edc0001925f90d5a6f0/ktlint/build.gradle.kts#L66.
The only options for this Maven plugin to work on Java 16+ are listed above.

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

3 participants