Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle: how to run lint automatically with check? #55

Closed
mverleg opened this issue Feb 11, 2018 · 7 comments
Closed

Gradle: how to run lint automatically with check? #55

mverleg opened this issue Feb 11, 2018 · 7 comments
Labels

Comments

@mverleg
Copy link
Contributor

mverleg commented Feb 11, 2018

I don't know if this is a bug or just my ignorance regarding Gradle, but I can't seem to do:

test.dependsOn ktlintCheck

I get this message:

A problem occurred evaluating root project 'lintsetup'.
  > Could not get unknown property 'ktlintCheck' for root project 'lintsetup' of type org.gradle.api.Project.

I created an otherwise clean project, which has a build.gradle like this:

buildscript {
    ext.kotlin_version = '1.2.21'

    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

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

group 'lintsetup'
version '1.0-SNAPSHOT'

apply plugin: 'kotlin-platform-jvm'

repositories {
    mavenCentral()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    testCompile "junit:junit:4.12"
    testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
    testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
}

test.dependsOn ktlintCheck
@JLLeitschuh
Copy link
Owner

We should support this. For now the solution is to do the following:

afterEvaluate {
    test.dependsOn ktlintCheck
}

@mverleg
Copy link
Contributor Author

mverleg commented Feb 14, 2018

Thanks for the answer!

I'm afraid it still doesn't work. I can use the task directly, but putting the suggested code in the top-level build.gradle (near the bottom) still gives the same error.

(Using a string ':topproject:ktlintCheck' moves the error to runtime but doesn't work)

@Tapchicoma
Copy link
Collaborator

Tapchicoma commented Feb 15, 2018

@mverleg note, that if you have multimodule project, root project will not have test or check tasks. You can archive it with following:

subprojects {
    afterEvaluate {
        if (it.plugins.findPlugin("org.jlleitschuh.gradle.ktlint") != null) {
            check.dependsOn("ktlintCheck")
        }
    }
}

@Tapchicoma
Copy link
Collaborator

Though I agree in general that check task should depend on ktlintCheck task.

@Tapchicoma
Copy link
Collaborator

Actually plugin already set check task to depend on all ktlint check tasks.

For example:

$ ./gradlew -m :samples:kotlin-ks:check
:samples:kotlin-ks:ktlintMainCheck SKIPPED
:samples:kotlin-ks:ktlintTestCheck SKIPPED
:samples:kotlin-ks:compileKotlin SKIPPED
:samples:kotlin-ks:compileJava SKIPPED
:samples:kotlin-ks:processResources SKIPPED
:samples:kotlin-ks:classes SKIPPED
:samples:kotlin-ks:compileTestKotlin SKIPPED
:samples:kotlin-ks:compileTestJava SKIPPED
:samples:kotlin-ks:processTestResources SKIPPED
:samples:kotlin-ks:testClasses SKIPPED
:samples:kotlin-ks:test SKIPPED
:samples:kotlin-ks:check SKIPPED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
See https://docs.gradle.org/4.5/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 0s

@mverleg can you check it for your project setup?

@mverleg
Copy link
Contributor Author

mverleg commented Feb 17, 2018

Yeah I made a sample and it does have the dependency by default for JVM project, so I think this will mostly be fixed by #58 .

Though it's worth noting that

test.dependsOn ktlintCheck

still gives the error from the first post, even for JVM. It's not really a problem since it already happens by default, but it's a little weird.

This does work for JVM, but not for other platforms:

afterEvaluate {
    test.dependsOn ktlintCheck
}

@Tapchicoma
Copy link
Collaborator

@mverleg feel free to reopen if it will not work for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants