Open dfiai opened 7 months ago
Hi @dfiai, the alternative is maven and gradle plugins with run-task
executor. check this repo for examples : https://github.com/khalilou88/jnxplus-examples
For nx-maven: 1- add plugin to root pom.xml or a parent-project:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>ktlint</id>
<configuration>
<target name="ktlint">
<java
taskname="ktlint"
dir="${basedir}"
fork="true"
failonerror="true"
classpathref="maven.plugin.classpath"
classname="com.pinterest.ktlint.Main"
>
<jvmarg value="--add-opens=java.base/java.lang=ALL-UNNAMED" />
<!-- see https://pinterest.github.io/ktlint/install/cli/#command-line-usage for more information -->
<arg value="src/**/*.kt" />
</java>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>ktlint-format</id>
<configuration>
<target name="ktlint">
<java
taskname="ktlint"
dir="${basedir}"
fork="true"
failonerror="true"
classpathref="maven.plugin.classpath"
classname="com.pinterest.ktlint.Main"
>
<jvmarg value="--add-opens=java.base/java.lang=ALL-UNNAMED" />
<!-- see https://pinterest.github.io/ktlint/install/cli/#command-line-usage for more information -->
<arg value="-F" />
<arg value="src/**/*.kt" />
</java>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.pinterest.ktlint</groupId>
<artifactId>ktlint-cli</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
</plugin>
2- add executors to project.json
:
"ktlint": {
"executor": "@jnxplus/nx-maven:run-task",
"options": {
"task": "antrun:run@ktlint"
}
},
"ktlint-format": {
"executor": "@jnxplus/nx-maven:run-task",
"options": {
"task": "antrun:run@ktlint-format"
}
}
@khalilou88 thank you! I'm using gradle, do you have an example for it?
For gradle: 1- add plugin https://github.com/JLLeitschuh/ktlint-gradle to build.gradle or build.gradle.kts
alias(libs.plugins.jlleitschuh.gradle.ktlint)
2- add executors to project.json
:
"ktlint": {
"executor": "@jnxplus/nx-gradle:run-task",
"options": {
"task": "ktlintCheck"
}
},
"ktlint-format": {
"executor": "@jnxplus/nx-gradle:run-task",
"options": {
"task": "ktlintFormat"
}
}
thank you!
I am not planning to add ktlint
to nx-maven or nx-gradle to keep the plugins simple but I will add this section to docs
What alternative should be used for linting in this case?