Hi all :android-wave: , I am trying to add a custo...
# detekt
a
Hi all 👋 , I am trying to add a custom rule by referencing this post - https://medium.com/@emrekoc/detekt-for-android-how-to-make-your-own-custom-rule-2861eb60e4ba. I am getting an error. Can anyone please help. thank you color
Error
Copy code
FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:detekt'.
> Could not resolve all task dependencies for configuration ':app:detektPlugins'.
   > Could not resolve project :rules.
     Required by:
         project :app
      > Cannot choose between the following variants of project :rules:
          - debugRuntimeElements
          - releaseRuntimeElements
        All of them match the consumer attributes:
          - Variant 'debugRuntimeElements' capability Finance Manager:rules:unspecified:
              - Unmatched attributes:
                  - Provides com.android.build.api.attributes.AgpVersionAttr '8.4.0' but the consumer didn't ask for it
                  - Provides com.android.build.api.attributes.BuildTypeAttr 'debug' but the consumer didn't ask for it
                  - Provides com.android.build.gradle.internal.attributes.VariantAttr 'debug' but the consumer didn't ask for it
                  - Provides org.gradle.category 'library' but the consumer didn't ask for it
                  - Provides org.gradle.jvm.environment 'android' but the consumer didn't ask for it
                  - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
                  - Provides org.jetbrains.kotlin.platform.type 'androidJvm' but the consumer didn't ask for it
          - Variant 'releaseRuntimeElements' capability Finance Manager:rules:unspecified:
              - Unmatched attributes:
                  - Provides com.android.build.api.attributes.AgpVersionAttr '8.4.0' but the consumer didn't ask for it
                  - Provides com.android.build.api.attributes.BuildTypeAttr 'release' but the consumer didn't ask for it
                  - Provides com.android.build.gradle.internal.attributes.VariantAttr 'release' but the consumer didn't ask for it
                  - Provides org.gradle.category 'library' but the consumer didn't ask for it
                  - Provides org.gradle.jvm.environment 'android' but the consumer didn't ask for it
                  - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
                  - Provides org.jetbrains.kotlin.platform.type 'androidJvm' but the consumer didn't ask for it

* Try:
> Ambiguity errors are explained in more detail at <https://docs.gradle.org/8.7/userguide/variant_model.html#sub:variant-ambiguity>.
> Review the variant matching algorithm at <https://docs.gradle.org/8.7/userguide/variant_attributes.html#sec:abm_algorithm>.
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at <https://help.gradle.org>.
n
We're going to need to see actual code to be helpful here
a
Hi @Nicholas Doglio, Thanks for replying, I am not sure what code is required. This is the repo: https://github.com/Abhimanyu14/finance-manager The custom rule itself doesn't have the issue as far I understand. The issue is most likely with the setup.
Please let me know if anything particular is required. thank you color
h
a
Hi @handstandsam, This creates the rules in a new repository. Can you please share how I can add custom rules to my existing repo?
h
It's a template for how to create an jar/library containing detekt rules and using service loader via the
resources/META-INF/...
config. Once you have a module like that, then you can use
detektPlugins(project(":my-detekt-rules"))
and they'll show up. In the detekt plugin config, you can set
debug = true
and it helps debugging.
a
Okay, so I can use this template and copy paste the result into my project directory?
h
I referenced the template a few days ago when doing the same. I don't know if a direct copy/paste will work, but I would clone the template and just get it to run, then understand the difference between your project.