Contrary to the default plugin setup this plugin is set up as a multi-module project. This is required as the Ktlint artifact for the KtlintRuleEngine encloses the embeddable Kotlin compiler which conflicts with the IDE compiler.
The "ktlint-lib" project relocates the conflicting classes, and provides the different versions of the rulesets. The "plugin" project uses the "lib" to include the (modified) Ktlint artifacts.
Once the plugin has been tested with the Run Plugin.run.xml run configuration, the development version of the plugin can also be installed on the local machine of yourself and other beta testers.
- Modify the name of the plugin
ktlint-plugin/src/main/resources/META-INF/plugin.xmland/or thepluginVersionin the (root)gradle.propertiesso that the specific version can be recognized easily:<name>Ktlint (dev-version YYYY-MM-DD)</name>
- Perform a clean build
- Run the Plugin so that the IDEA sandbox is refreshed
- Create zip file with development version of plugin from IDEA sandbox
./create-ktlint-plugin-zip.sh
- Install the zip file manually using Preferences > Plugins > ⚙️ > Install plugin from disk...
The ktlint-lib module contains all version of the ktlint rules which are supported by the plugin.
To support a new version (X.Y.Z) of ktlint, the following needs to be done:
- Duplicate the latest
ruleset-A-B-Cmodule inktlint-lib. This module only contains abuild.gradle.ktsfile. This file needs to be changed as follows:- In the
dependenciesblock refer to the new ktlint versionX.Y.Z(use a snapshot version when applicable)dependencies { implementation("com.pinterest.ktlint:ktlint-ruleset-standard:X.Y.Z-SNAPSHOT") } - In the
relocateblock change the coordinates of theStandardRulesetProvideras follows (note that only the minor versionYneeds to be left padded with a 0 to support up to 99 minor versions):relocate( "com.pinterest.ktlint.ruleset.standard", "com.pinterest.ktlint.ruleset.standard.VX_YY_Z", )
- In the
- In class
KtlintRulesetVersionadd a new enum entry below enum entryDEFAULT:Note: the required importDEFAULT("default (recommended)", null), VX_Y_Z("X.Y.Z", StandardRuleSetProviderVX_0Y_Z()),
com.pinterest.ktlint.ruleset.standard.VX_0Y_Z.StandardRuleSetProvider as StandardRuleSetProviderVX_0Y_Zwill not be valid until all steps have been completed and the build has succeeded. - In the
dependenciesblock ofktlint-lib/build.gradle.ktsadd following:compileOnly(project(":ktlint-lib:ruleset-X-Y-Z")) // Required for IDE implementation(project(":ktlint-lib:ruleset-X-Y-Z", "shadow"))
- In field
rulesetVersionin fileKtlintConfigFormadd the new optionX.Y.Zjust below valuedefault (recommended). Note that this value should be identical to the value of thelabelused in the enum entry inKtlintRulesetVersion. - In the
includeblock in the rootbuild.gradle.ktsadd following:"ktlint-lib:ruleset-X-Y-Z",
Note: the total size of the plugin grows with approximately 1 MB per ruleset version which is added.
Snapshots of ktlint are published on Sonatype https://oss.sonatype.org/content/repositories/snapshots/com/pinterest/ktlint/
Add following section to the build.gradle.kts of the ktlint-lib module:
allprojects {
repositories {
mavenCentral()
maven("https://oss.sonatype.org/content/repositories/snapshots")
}
}In gradle/libs.version.toml change the ktlint setting to the snapshot-version.
In case you want to build with a local version of ktlint which is not yet published to Sonatype, then add following section to the build.gradle.kts of the ktlint-lib module instead:
allprojects {
repositories {
mavenCentral()
// Comment out next line before publish on default channel. It is okay to keep it when publishing to beta or dev channels
maven("https://oss.sonatype.org/content/repositories/snapshots")
// Comment out next line before publishing to any channel
mavenLocal()
}
}Note: In the "ktlint" project execute ./gradlew publishMavenPublicationToMavenLocal to publish the SNAPSHOT artifacts to your local maven repository!