-
-
Notifications
You must be signed in to change notification settings - Fork 771
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
Add automatic detekt tasks for Android Plugins #2787
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2787 +/- ##
============================================
- Coverage 79.76% 79.56% -0.21%
- Complexity 2507 2527 +20
============================================
Files 427 431 +4
Lines 7542 7639 +97
Branches 1421 1441 +20
============================================
+ Hits 6016 6078 +62
- Misses 771 795 +24
- Partials 755 766 +11
Continue to review full report at Codecov.
|
Hrm... I still seem to be doing something else wrong. When this task is run, my custom rule in my project fails to execute, because it cannot determine the absolute path of the incoming |
I eventually opened https://issuetracker.google.com/issues/158777988 for the |
Please try to rebase on current master. |
3bb75c7
to
28f758d
Compare
Build is broken - the new
It's part of the locally-published POM: <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- This module was also published with a richer model, Gradle metadata, -->
<!-- which should be used instead. Do not delete the following line which -->
<!-- is to indicate to Gradle or any Gradle module metadata file consumer -->
<!-- that they should prefer consuming it instead. -->
<!-- do_not_remove: published-with-gradle-metadata -->
<modelVersion>4.0.0</modelVersion>
<groupId>io.gitlab.arturbosch.detekt</groupId>
<artifactId>detekt-gradle-plugin</artifactId>
<version>1.10.0-RC1-android-gradle-plugin</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.gitlab.arturbosch.detekt</groupId>
<artifactId>detekt-bom</artifactId>
<version>1.10.0-RC1-android-gradle-plugin</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
... |
Ok, I manually added the missing POM file for <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>io.gitlab.arturbosch.detekt</groupId>
<artifactId>detekt-bom</artifactId>
<version>1.10.0-RC1</version>
<name>detekt</name>
<packaging>pom</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.78</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.26</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-html-jvm</artifactId>
<version>0.7.1</version>
</dependency>
</dependencies>
</dependencyManagement>
</project> |
This solved the issue with my custom rule not finding the KtFile's path. Analysis runs through in general, just that I still see a lot of compilation errors beforehand (that don't break the task). I don't know how exactly Detekt's type resolution works, but I guess issues that stem from synthetic imports won't be resolvable, because the compiler plugin generating code for those doesn't place that generated code anywhere visible.
|
The bom will be published with #2814 |
detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/DetektPlugin.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does android need the synthetic props/files while running detekt
or for a sourceset?
Does it help if you explicitly add them to DetektExtension.input
?
detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/DetektPlugin.kt
Show resolved
Hide resolved
Can't think of any, no. Just the source files should be enough IMHO. |
I'll come back to this in a few weeks, right now it's release crunching time here and I have no more time to spent on this PR. I'll keep it open until then and then rebase against the recent master. |
2efb6a5
to
4c2b53b
Compare
Would be happy if somebody could re-review this. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good to me.
Could you elaborate why we technically need two Gradle plugins to support Android?
Shouldn't project.plugins.withId("kotlin-android") {...}
to enough to not run into android specific code?
detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/KotlinExtension.kt
Outdated
Show resolved
Hide resolved
I'm not sure if I understand the question. The original reviewer's comment was that the Android-specific things should not become a burden for non-Android projects, so no Android-specific dependencies should be in the original plugin's code. I understood that and followed along. I figured however that there was no other easy and maintainable way to query the Android Gradle Plugin's API except for referencing it, the alternative would have be to write a lot of class loading magic. The other thing is in many projects Android modules and pure JVM modules are intermixed. My aim was to have a single plugin (the new android plugin) to handle both, without code and configuration duplication. That's why I also created those aggregation tasks, |
@arturbosch I opened up a separate, experimental sub PR to figure out how feasible it is to generate a baseline file with type resolution enabled, but I stumbled upon a weird issue. Could you comment there? realdadfish#1 |
Issue solved in a separate PR here. #2879 |
So, the TR-enabled baseline creation is working nicely alongside checking. I will add a couple of more integration tests to check whether the appropriate tasks are actually created once I got some feedback on the implementation. I kind of "hacked" the configuration of the baseline file and dynamically extend it's name with the sourceSet or variant name. I don't like this approach all too much; the alternative would have been to not configure a single baseline file, but to provide a directory where these files reside (configure Feedback is welcome! |
Thanks for the fix! It will take me some time to review this PR. I will come back to you in a few days. |
@arturbosch Have you had time to look at the PR yet? I'm working with a fork right now and would really like to get this "upstream-ready" :) |
Sorry for the delay. Unfortunately no, not yet. I will take time for this PR this week. Thanks for the reminder and the patience. |
Hey, sorry for the wait!
Any idea why this is happening? I can successfully build |
I meant that if you protect code which uses Android specific methods/references with |
Can you give me the full stacktrace? Then I can investigate why the Gradle plugin asks for the SDK at this stage. I don't know the ktlint plugin enough to answer your second question. |
Ok, had to re-read on class-loading, because my original assumption was that if I want to be truly "compatible" I'd have to use a lot of reflection in my code, but apparently popular JVMs have some loopholes and it might be enough to move the Android-specific code in separate classes, eventually even only into a separate method (cf. https://stackoverflow.com/a/34263422/305532). I try to come up with a better solution then.
It was given by schalkms on the Kotlin Slack at
Well, the amount of tests would stay the same if I'd merge both, but in any case one could speed up the tests in-module with parallelism (higher fork-count) eventually if this is an issue.
Again, don't know the innards of ktlint-gradle, but I try my best. |
a42e70c
to
1bb3e69
Compare
@arturbosch I rebased to current master and merged the implementation back into the main plugin. Let me know what you think. |
1bb3e69
to
0c139e3
Compare
If this is ready for prime-time, I should probably document the configuration options and meta tasks / potential pitfalls as well as the configuration file fallback somewhere. What would be a good place to do so? |
I suppose that here is the best place: https://github.com/detekt/detekt/blob/master/docs/pages/gettingstarted/gradle.md if it gets big we can split it later. |
0c139e3
to
9c8c213
Compare
The code looks good. @BraisGabin can you check how it behaves with one of your Android projects, please? |
@arturbosch These warnings appear only for Things to note: Baseline files are recognized by source set or variant name, while the latter takes precedence. That means if both, a |
9c8c213
to
53ccca8
Compare
53ccca8
to
f408a96
Compare
I've added some documentation to |
TL;DR: Ready to merge. I did a quick fix to make it compile. But I'm not sure if I could break something (I know nearly nothing about gradle scriptting) Things that I found:
Neigther of those seem like blockers. I think that this is a huge improvement. We can mark the support to Android as "experimental" so we can break things when we get some feedback from the community. |
Yes, the
This is a hard problem, because each analysis sees basically "two different versions" of the same module. What I could think about in general however is some kind of "merge" task, similar to what Jacoco also provides for it's binary format. We'd however have to separate analysis from report generation task-wise, and I don't know how feasible this is to do right now, given the fact that the development goes towards a compiler plugin. |
I have a lot of false positives in the rule Then I have false positives in binding.address2?.visibility = if (state.address == null) GONE else VISIBLE The problem is that I really don't know if these issues are in the plugin, my setup or the rules. |
@BraisGabin I've recently upgraded to Rx3 (3.0.6) as well and got no additional warnings from Detekt wrt Regarding databinding (this is databinding, and not synthetic accessors, right?), we don't use safe-calls on those, so we don't see those warnings there either. |
Yes... probably a problem in my setup? I have issues in code like: Observable.just("hi")
.observeOn(main) // This line
.subscribe()
.addTo(compositeDisposable) or return if (something) {
Observable.just("hi") // this line
} else {
Observable.just("hello") // and this line too
}
It is But I'm wondering how detekt should behave about this errors... Manage the case that one class is not correctly solved in the rule doesn't seem rule-writter friendly... So maybe we should just don't care about it. This will be fixed with the compile plugin so add that complexity to the rules doesn't seem a good idea. |
Cool :) lets merge this then, looks good @realdadfish thanks for the contribution! |
🎉🎉🎉🎉🎉 Great contribution @realdadfish |
The Gradle Plugin was missing automatic task generation for Android modules, so I tried adding them.
While this works in general, I still get a couple of compilation issues when running the task on different modules, mainly things that stem from code generation: