nbadal / ktlint-intellij-plugin

Ktlint plugin for IntelliJ IDEA + Android Studio
MIT License
150 stars 22 forks source link

Plugin set

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.

Installation

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.

Adding a ktlint ruleset

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:

Note: the total size of the plugin grows with approximately 1 MB per ruleset version which is added.

Building with ktlint SNAPSHOT version

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!