gantsign / ktlint-maven-plugin

Maven plugin for ktlint the Kotlin linter

Home Page:http://gantsign.com/ktlint-maven-plugin/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

aperusset opened this issue · comments

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 !

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.

commented

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

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.