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
plugin/src/main/resources/META-INF/plugin.xml
and/or thepluginVersion
in the (root)gradle.properties
so 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-C
module inktlint-lib
. This module only contains abuild.gradle.kts
file. This file needs to be changed as follows:- In the
dependencies
block 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
relocate
block change the coordinates of theStandardRulesetProvider
as follows (note that only the minor versionY
needs 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
KtlintRulesetVersion
add 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_Z
will not be valid until all steps have been completed and the build has succeeded. - In the
dependencies
block ofktlint-lib/build.gradle.kts
add following:compileOnly(project(":ktlint-lib:ruleset-X-Y-Z")) // Required for IDE implementation(project(":ktlint-lib:ruleset-X-Y-Z", "shadow"))
- In field
rulesetVersion
in fileKtlintConfigForm
add the new optionX.Y.Z
just below valuedefault (recommended)
. Note that this value should be identical to the value of thelabel
used in the enum entry inKtlintRulesetVersion
. - In the
include
block in the rootbuild.gradle.kts
add 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!