lampietti/ktlint-gradle


A ktlint gradle plugin

Download


Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}
	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.lampietti:ktlint-gradle:v2.1.1'
	}
	<dependency>
	    <groupId>com.github.lampietti</groupId>
	    <artifactId>ktlint-gradle</artifactId>
	    <version>v2.1.1</version>
	</dependency>

                            
    libraryDependencies += "com.github.lampietti" % "ktlint-gradle" % "v2.1.1"
        
        

                            
    :dependencies [[com.github.lampietti/ktlint-gradle "v2.1.1"]]
        
        

Readme


Ktlint Gradle

Join the chat at https://gitter.im/ktlint-gradle/Lobby Build Status

Provides a convenient wrapper plugin over the ktlint project.

This plugin can be applied to any project but only activates if that project has the kotlin plugin applied. The assumption being that you would not want to lint code you weren't compiling.

Warning

This plugin was written using the new API available for gradle script kotlin builds. This API is available in new versions of gradle.

This plugin has only been tested with gradle 3.5 and should work with versions 3.5+.

If you find this plugin works with older versions feel free to update this readme to reflect this.

How to use

Build script snippet for use in all Gradle versions:

buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "gradle.plugin.org.jlleitschuh.gradle:ktlint-gradle:2.2.1"
  }
}

apply plugin: "org.jlleitschuh.gradle.ktlint"

Build script snippet for new, incubating, plugin mechanism introduced in Gradle 2.1:

plugins {
  id "org.jlleitschuh.gradle.ktlint" version "2.2.1"
}

Configuration

The following configuration block is optional.

If you don't configure this the defaults defined in the KtlintExtension object will be used. The version of Ktlint used by default may change between patch versions of this plugin. If you don't want to inherit these changes then make sure you lock your version here.

ktlint {
    version = ""
    debug = true
    verbose = true
    reporter = "checkstyle"
    ignoreFailures = true
}

Tasks Added

This plugin adds two tasks to every source set: ktlint[source set name]Check and ktlint[source set name]Format. Additionally, a simple ktlintCheck task has also been added that checks all of the source sets for that project. Similarly, a ktlintFormat task has been added that formats all of the source sets.

If project has subprojects - plugin also adds two meta tasks ktlintCheck and ktlintFormat to the root project that triggers related tasks in subprojects.

Developers

Building

./gradlew build

Future Development

Add support for linting *.kts for gradle script kotlin builds.

Links

Ktlint Gradle Plugin on the Gradle Plugin Registry