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

Using detekt in a precompiled Gradle script #6895

Closed
imashnake0 opened this issue Jan 22, 2024 · 3 comments
Closed

Using detekt in a precompiled Gradle script #6895

imashnake0 opened this issue Jan 22, 2024 · 3 comments

Comments

@imashnake0
Copy link

Expected Behavior

I'm trying to use detekt in a precompiled Gradle script. I can't seem to apply the precompiled script plugin to a specific module. See #3490 (comment) and https://github.com/imashnake0/Detekt-Convention.

Observed Behavior

Build fails with:

Unable to load class 'com.android.build.gradle.BaseExtension'
com.android.build.gradle.BaseExtension

Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)

Re-download dependencies and sync project (requires network)
The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.

Stop Gradle build processes (requires restart)
Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

Steps to Reproduce

  1. Create a new project
  2. Create a detekt precompiled script in the buildSrc module.
  3. Build fails.

Context

I'm trying to configure detekt and use it as a precompiled script (instead of a detekt.gradle script plugin) as mentioned here: #3490 (comment).

@cortinico Is there any chance you could create a sample to showcase how detekt can be used in a precompiled script?

Your Environment

  • Version of detekt used: 1.23.4
  • Version of Gradle used (if applicable): 8.5
  • Gradle scan link (add --scan option when running the gradle task): N/A
  • Operating System and version: macOS 12.7.2
  • Link to your project (if it's a public repository): https://github.com/imashnake0/Detekt-Convention
@imashnake0 imashnake0 added the bug label Jan 22, 2024
@BraisGabin
Copy link
Member

What should I do on that project to reproduce your problem? If I run test everything works. If I run detekt it says:

Task 'detekt' not found in root project 'Detekt Convention' and its subprojects.

So you just didn't configure detekt at all there.

@imashnake0
Copy link
Author

imashnake0 commented Jan 26, 2024

@BraisGabin Apologies, I didn't push my changes. Applying the plugin like this results in the error I posted above: https://github.com/imashnake0/Detekt-Convention/blob/8d9b957f337c785f840303db75e806101d55d8a2/app/build.gradle.kts#L4

Let me know if you can provide a sample for using detekt via a precompiled script.

@BraisGabin
Copy link
Member

BraisGabin commented Jan 27, 2024

I can reproduce the error but I'm not sure what's going on. I don't use buildSrc I create a build-logic similar to what detekt does itself. And it works for me. There I have somethig like this:

fun Project.setupDetekt(vararg buildVariats: String) {
    pluginManager.apply("io.gitlab.arturbosch.detekt")

    extensions.configure<io.gitlab.arturbosch.detekt.extensions.DetektExtension> {
        baseline = file("baseline.xml")
    }

    ...

And then on my scripts I add setupDetekt() (to be honest, that's not 100% sure, I have other functions and other plugins on top of all of that, but the idea is that). I'm closing as I think that this is not a detekt issue. If you find anything that points in other direction don't hestiate to comment or even reopen.

@BraisGabin BraisGabin closed this as not planned Won't fix, can't repro, duplicate, stale Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants