Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Running tasks from command line #114

Closed
bitsydarel opened this issue Jul 15, 2018 · 10 comments
Closed

Running tasks from command line #114

bitsydarel opened this issue Jul 15, 2018 · 10 comments

Comments

@bitsydarel
Copy link

When building the project the only static analysis tool check is detekt even when verifying the list of tasks available I don't see findbugs,pmd,checkstyle tasks . Is there's any way to run all the checks ?

@tasomaniac
Copy link
Contributor

Hi @bitsydarel

Would be great if you can post code from your setup. Is it an Android project? If you do the setup similar to our sample, you should see lots of tasks with names starting with findbugs, pmd and checkstyle

@bitsydarel
Copy link
Author

bitsydarel commented Jul 15, 2018

Sure @tasomaniac .
Yes it's a multi module android project.
settings are almost the same with sample project.

capture d ecran de 2018-07-15 17-28-42

sicne we have a lot of build flavor and we only want to run check when building for debug buildtype:
my analisys-task.gradle content is:
tasks.whenTaskAdded { task ->
if (task.name.contains("assemble") && task.name.contains("Debug")) {
task.finalizedBy check
}
}

static-analysis.gradle file content is:
apply plugin: 'com.novoda.static-analysis'
apply plugin: 'io.gitlab.arturbosch.detekt'

staticAnalysis {
penalty {
maxErrors = 0
maxWarnings = 0
}

checkstyle {
    exclude project.fileTree('src/test/java')
    exclude '**/*.kt'
    configFile rootProject.file('team-props/checkstyle-modules.xml')
    includeVariants { variant -> variant.name.contains('debug') }
}

pmd {
    exclude project.fileTree('src/test/java')
    exclude "**/*.kt"
    ruleSetFiles = rootProject.files('team-props/pmd-rules.xml')
    ruleSets = []
    includeVariants { variant -> variant.name.contains('debug') }
}

findbugs {
    version = "1.0.0.[version]"
    effort = 'max'
    reportLevel = "medium"
    showProgress = true
    includeFilter = file("$rootProject.projectDir/config/findbugs/*.xml")
    excludeFilter = file("$rootProject.projectDir/config/findbugs/*.xml")
    includeVariants { variant -> variant.name.contains('debug') }
}

lintOptions {
    checkReleaseBuilds false
    warningsAsErrors true
}

detekt {
    debug = true
    profile("main") {
        input = "$projectDir/src/main/java"
        config = rootProject.file('team-props/detekt-config.yml')
        filters = '.*test.*,.*/resources/.*,.*/tmp/.*'
        output = "$projectDir/build/reports/detekt"
    }
}

}

app module build.gradle content:
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
maven { url "https://plugins.gradle.org/m2/" }
}

dependencies {
    //noinspection GradleDynamicVersion
    classpath 'io.fabric.tools:gradle:1.+'
    classpath "net.ltgt.gradle:gradle-errorprone-plugin:+"
    classpath 'com.novoda:gradle-static-analysis-plugin:+'
}

}

plugins {
id 'io.gitlab.arturbosch.detekt' version '1.0.0.RC6-3'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'
apply plugin: 'org.sonarqube'
apply plugin: 'realm-android'
apply plugin: "net.ltgt.errorprone"
apply from: rootProject.file('team-props/static-analysis.gradle')
apply from: rootProject.file('team-props/analysis-task.gradle')
*************************************** other configurations **********************************

gradle graph by module:
capture d ecran de 2018-07-15 17-34-03

verification checks:
capture d ecran de 2018-07-15 17-35-53

@tasomaniac
Copy link
Contributor

Hey, thanks for the detailed reply. The problem is probably is the following line.

variant.name.contains('debug')

Variant name almost never contains lower case 'debug' sonce you have flavors. You either want to do 'toLowercase()' first. Or you can also use 'variant.debugable' directly. 'debugable' is a Boolean property on the Variant class in Android plugin.

@bitsydarel
Copy link
Author

Ho I see, well, I took it from the multi-module sample project but it's made sense.

I just tried that, I received:Could not get unknown property 'debugable' for object of type com.android.build.gradle.internal.api.TestVariantImpl.
I think it's make sense because the property is set on the buildType, so either I get the buildType and retrieve the value or I use the "Debug" string.

Will all the tasks be added to the gradle check task?

@tasomaniac
Copy link
Contributor

All tasks are added to 'evaluateViolations' task.

I think I made a typo, can you check with 'debuggable'? With double g?

@bitsydarel
Copy link
Author

Working with "Debug" because if buildFlavor is lol the buildVariant will be lolDebug.
Should i worry about checkStyle for android tests? even thought i excluded them...
capture d ecran de 2018-07-15 17-53-23

same error for debuggable so like i said you can only retrieve it directly from the buildType object.
Could not get unknown property 'debuggable' for object of type com.android.build.gradle.internal.api.TestVariantImpl.

@tasomaniac
Copy link
Contributor

I see. Glad that it worked.
You can also filter 'AndroidTest' in the variant filter.

@bitsydarel
Copy link
Author

Thanks for the help.

@bitsydarel
Copy link
Author

bitsydarel commented Jul 15, 2018

Last question, which task should I run if I want to run all tools ? Check or evaluate violations ?

@bitsydarel
Copy link
Author

Resolved

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

No branches or pull requests

2 participants