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

Applying plugin to subprojects doesn't work #826

Closed
ydavygora opened this issue Jan 17, 2025 · 5 comments
Closed

Applying plugin to subprojects doesn't work #826

ydavygora opened this issue Jan 17, 2025 · 5 comments

Comments

@ydavygora
Copy link

ydavygora commented Jan 17, 2025

Hello,

I'm running into an issue with a multiproject setup (using Gradle 8.12). My top level build.gradle.kts is minimal:

plugins {
    id("org.jlleitschuh.gradle.ktlint") version ("12.1.2")
}

allprojects {
    repositories {
        mavenCentral()
    }
}

subprojects {
    // apply(plugin = "org.jlleitschuh.gradle.ktlint")
}

ktlint {
    version = "1.5.0"
}

If I leave the line commented, then the code in the subprojects does not get formatted/checked. If I uncomment the line, here's the error I get:

./gradlew clean ktlintFormat

FAILURE: Build failed with an exception.

* What went wrong:
org/jetbrains/kotlin/gradle/dsl/KotlinProjectExtension
> org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension

* Try:
> 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.

If I run this with stacktrace, the first three lines are:

* Exception is:
java.lang.NoClassDefFoundError: org/jetbrains/kotlin/gradle/dsl/KotlinProjectExtension
        at org.jlleitschuh.gradle.ktlint.KtlintPlugin$applyKtLint$1.invoke(KtlintPlugin.kt:81)
        at org.jlleitschuh.gradle.ktlint.KtlintPlugin$applyKtLint$1.invoke(KtlintPlugin.kt:19)
        at org.jlleitschuh.gradle.ktlint.KtlintPlugin$sam$org_gradle_api_Action$0.execute(KtlintPlugin.kt)
...

To be honest, I am not sure if I am doing anything wrong or if there is a bug in the plugin. In any case I would be really grateful for your assistance. If you need more input from me (more logs, a minimal working or, rather, failling example), please let me know and thank you very much in advance!

@ydavygora
Copy link
Author

Minimal example: https://github.com/ydavygora/ktlint_example

@matsudamper
Copy link

What about adding it to root's build.gradle.kts?

plugins {
    id("org.jlleitschuh.gradle.ktlint") version ("12.1.2")
+    kotlin("jvm") version ("2.1.0") apply false
}

@ydavygora
Copy link
Author

Hi @matsudamper ,

the apply false kind of defeats the purpose of having it at the root project level. My intention was for it to not only format/lint the code in subprojects, but also to format the build.gradle.kts and settings.gradle.kts files in the root project. It's just a nitpicky thing, and it's by no means any high priority or anything, I was just wondering if there was a way to format files both in the root project and subprojects. But I can also live with formatting the two kts files in the root project manually, it's not like they change very often

@ydavygora
Copy link
Author

Oh, sorry @matsudamper , I misunderstood you. You were talking about the kotlin-jvm plugin, not the ktlint plugin. I will try this, thanks!

@ydavygora
Copy link
Author

It works! Thank you very much again, @matsudamper and sorry for the initial misunderstanding!

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

2 participants