JLLeitschuh / ktlint-gradle

A ktlint gradle plugin
MIT License
1.47k stars 160 forks source link

ktlintCheck always successful #291

Closed yusufceylan closed 5 years ago

yusufceylan commented 5 years ago

I am trying to integrate ktlint to my project.

My project level gradle file


buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

allprojects {
    repositories {
        google()
        jcenter()

    }
    apply plugin: "org.jlleitschuh.gradle.ktlint" // Optionally apply plugin to all project modules and Version should be inherited from parent
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

I also break some rules for checking and here is my Activity

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }
}

When I call gradlew ktlintCheck command, build is always successful even if I already break some rules.

Gradle Version 5.4.1 Android Gradle Plugin Version 3.5.1 Android Studio Version 3.5.1

Any idea why this is happening?

Tapchicoma commented 5 years ago

You should not mix old and new way of applying plugins. Check the second entry in FAQ section.

yusufceylan commented 5 years ago

Sorry @Tapchicoma but I do not understand clearly. I changed my project gradle file with this but still same.

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath "org.jlleitschuh.gradle:ktlint-gradle:9.0.0"
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

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

Also found a video tutorial and followed it but still always successful

Tapchicoma commented 5 years ago

In the change above you've missed applying this plugin to all subprojects:

allprojects {
    apply plugin: "org.jlleitschuh.gradle.ktlint"
}
yusufceylan commented 5 years ago

It works now, thanks a lot @Tapchicoma