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

Cannot apply to buildSrc #743

Open
pkubowicz opened this issue Jan 19, 2024 · 4 comments
Open

Cannot apply to buildSrc #743

pkubowicz opened this issue Jan 19, 2024 · 4 comments

Comments

@pkubowicz
Copy link

When I add the plugin to buildSrc/build.gradle.kts:

plugins {
    `kotlin-dsl`
    id("org.jlleitschuh.gradle.ktlint") version "12.0.3"
}

configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
    version.set("1.1.1")
    filter {
        include("**/*.kts")
        exclude { element -> element.file.path.contains("/generated-sources/") }
    }
}

it fails on classes generated by Gradle, even though I explicitly instruct the plugin not to include them.

buildSrc/build/generated-sources/kotlin-dsl-external-plugin-spec-builders/kotlin/gradle/kotlin/dsl/plugins/_bf0f0d1de34ae2a280c4b3e0ab359712/PluginSpecBuilders.kt:32:9 Package name must not contain underscore (cannot be auto-corrected) (standard:package-name)
@JLLeitschuh
Copy link
Owner

Can you share a build scan?

Also, a minor reproducer would be nice.

@wakingrufus we could probably automatically filter out this directory when the kotlin-dsl plugin is applied. Thoughts?

@pkubowicz
Copy link
Author

The scan is here: https://scans.gradle.com/s/enzehbyek47qs

Attached a simple reproducer.
gradle-kotlin-buildsrc.zip

@wakingrufus
Copy link
Collaborator

Can you share a build scan?

Also, a minor reproducer would be nice.

@wakingrufus we could probably automatically filter out this directory when the kotlin-dsl plugin is applied. Thoughts?

We could. I don't see this problem in regular projects using the kotlin-dsl plugin, so what is different about buildSrc that causes this?

@xenomachina
Copy link

tl;dr: It looks like something is getting cached in buildSrc/.gradle/buildOutputCleanup/ that's preventing changes to excludes from being honored.


I ran into this same problem: ktlint was reporting errors in the Kotlin code that Gradle generates in buildSrc/. I added an exclude like this...

ktlint {
    filter {
        exclude {
            it.file.relativeTo(projectDir).startsWith(File("build"))
        }
    }
}

...and it continued reporting these errors. Eventually I used git clean to delete all ignored files from my repo, and then it started working.

I was able to narrow the problem down to buildSrc/.gradle/buildOutputCleanup/ by conducting the following series of tests:

  • Start from a clean repo, with the above exclude: WORKS
  • Remove exclude: FAILS
  • Add exclude back: FAILS
  • rm -rf buildSrc/.gradle/: WORKS
  • Remove exclude: FAILS
  • Add exclude back: FAILS
  • rm -rf buildSrc/.gradle/kotlin/: FAILS
  • rm -rf buildSrc/.gradle/buildOutputCleanup/: WORKS
  • Remove exclude: FAILS
  • Add exclude back: FAILS
  • rm -rf buildSrc/.gradle/buildOutputCleanup/: WORKS

"WORKS" and "FAILS" indicate the outcome of running ./gradlew :buildSrc:ktlintCheck after the corresponding operation.

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

No branches or pull requests

4 participants