Make evaluateViolations task run for specific buildVariant #115
Comments
What about the variantFilter? Is that not solving this problem? |
No, because variant filter does not allow to dynamically choose a variant to include. |
So if I have to run checks for each build I have to change the included variant everytime I want to run static analysis tool for a specific variant... Which is not ideal. |
I think this is really nice to have. I'm really curious why the tasks were designed to have only single Here is a "hack/trick" or "gradle magic" that you can use to achieve what you want. Have this following variant filter in your configurations. This was you will be able to configure it from command line. You can run staticAnalysis {
lintOptions {
includeVariants {
it.name == project.properties['checkVariant']
}
}
} On top of that, you can also make use of applicationVariants.all { variant ->
project.tasks.create("evaluateViolations${variant.name.capitalize()}", GradleBuild) {
startParameter = gradle.startParameter.newBuild() // copy from the real build. Needs to come first
tasks = [ 'evaluateViolations' ]
startParameter.projectProperties['checkVariant'] = variant.name
}
} Note: |
@tasomaniac Sorry for the delay, To get the current buildVariant i have this function:
The issue is that it's only work when building from android studio but from jenkins nope, that's because the iml file is created by android studio but for now this is not an issue. LintOptions completly ignore the includeVariants, that was my first try by the way. So if i understand, GradleBuild will create an new build related to each buildvariant. But i don't understand the purpose of this line : so the only important configuration here is
|
Well, it is because you are able to parameterize and have different configurations for evaluateViolations with this trick. You can create flavor and buildType dependant variations of the same task but dynamically configure that differently. |
I see, thank you very much for the suggestions. |
My suggestion is a workaround/hack. I personally think this would be good for the plugin. |
I think I somehow missed this issue. It looks like an interesting request: we should be able to create specific |
To be honest, Android approach with flavors is powerful but makes everything complicated. I don't think any of the tools we support handles this situation. Your suggestion makes sense to me, although I think we need to make it super clear. |
The thresholds are not configuration dependent? So why not just generate different configuration for each flavor? |
@bitsydarel, to be honest I am pretty confused by your messages, so I will try to clarify few points. Apologies in advance if I am stating obvious things, I just want to be sure we're on the same page. Gradle builds in Android (and specifically the Android Gradle Plugin) support build variants but there is no such a thing as "selected variant"; that instead is a feature of the IDE that decides to just enable one build variant per module to allow you to work comfortably. This is basically the same as disabling variants using When you say "building from Android Studio" I am not sure what you mean, as the default run configuration to build the app definitely doesn't run Building from command line (like Jenkins will do, or like you do using the terminal integrated in your IDE) means that you are just using Gradle, no IDE gimmick, hence you will experience the standard behaviour of the build script, where all the build variants are active for an Android module unless explicitly disabled (ie: via What @tasomaniac suggested is a clever use of a nested build to keep using The thing I'm not onboard with at all is to provide thresholds and tool configurations per-variant: that will add IMO a level of complexity and a whole new level of edge cases that I am not really sure will be worth the effort. Consider again that as @tasomaniac mentioned none of the static analysis tools supported by this plugin is build variant-aware, not even Android lint, where the configuration is using the In conclusion: this plugin already offers |
Thanks for the suggestions, that's actually what I did at first and it's currently configured that way in our Jenkins. But I wanted to also make it dynamically in android studio so my colleagues can run checks before doing a pull request. The issue was that even after applying the incudeVariants it's still compile other variants and since we have many variants it's take time to build ... |
Unfortunately static analysis takes a long time, there's not much to do about it. Running Detekt and KtLint is fast because they don't compile the app, but Android Lint takes forever. You can optimise your setup a bit, but it'll still be very slow. Checkstyle, Findbugs and PMD are all kinds of slow, and there's very little you can do to make them faster unfortunately. If you have a mixed Java + Kotlin project then it'll take even longer since compilation will be slower, especially if you have apt + kapt in action, since the Kotlin compiler needs to be invoked more than once (before and after All that is hardly fixable in a meta-plugin such as this; we can't even do things such as using PMD incremental support as Gradle's PMD plugin doesn't support it yet either. Having almost all the supported tools being non-Android specific makes things even harder; trying to selectively compile things is near impossible to obtain without going crazy either... and it's still not going to solve all the perf issues outlined above, unfortunately. |
Guys, I think, tasks for specific buildVariant is useful. Using |
When running evaluateViolations in a project with multiple buildFlavors. The task compile all the buildVariants even if we're running the build for a specific buildVariant. Because of this behavior it's increases the time it's take for all the checks to run even on small projects.
The text was updated successfully, but these errors were encountered: