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

Confused on how to use custom rules #695

Closed
dondod opened this issue Jul 20, 2023 · 4 comments
Closed

Confused on how to use custom rules #695

dondod opened this issue Jul 20, 2023 · 4 comments
Assignees

Comments

@dondod
Copy link

dondod commented Jul 20, 2023

Hi, I have a gradle project with a main project (I'll call main-project) and another project that contains custom ktlint rules called ktlint-custom-rules. I've verified that my rules work when run with the latest (0.50.0) command-line ktlint runner. However, I haven't been able to get the custom rules to be recognized when running ktlintCheck against the main-project.

My build.gradle file in the ktlint-custom-rules looks like this:

apply plugin: "kotlin"

dependencies {
    runtimeOnly("com.pinterest.ktlint:ktlint-rule-engine:0.50.0")
    runtimeOnly("com.pinterest.ktlint:ktlint-rule-engine-core:0.50.0")
    implementation("com.pinterest.ktlint:ktlint-cli-ruleset-core:0.50.0")
    testImplementation("com.pinterest.ktlint:ktlint-test:0.50.0")
}

In the build.gradle file in main-project, I have this:

//...

plugins {
    id "org.jlleitschuh.gradle.ktlint" version "11.5.0"
}

apply plugin: 'org.jlleitschuh.gradle.ktlint'

dependencies {
    ktlintRuleset(project(":ktlint-custom-rules"))
}

Any ideas? I'm guessing I'm missing something simple here.

@SumeraMartin
Copy link

Do you have META-INF/services/com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3 file created? (It was required in the previous versions. Currently it is not working for me and I have a feeling that it is broken in this library.)

https://github.com/pinterest/ktlint/blob/master/ktlint-cli-ruleset-core/src/main/kotlin/com/pinterest/ktlint/cli/ruleset/core/api/RuleSetProviderV3.kt

@dondod
Copy link
Author

dondod commented Aug 3, 2023

Yes, pretty sure I had the RuleSetProviderV3 file when I filed this GitHub issue. I've since just used ktlint directly as documented here under Custom Gradle Installation: https://pinterest.github.io/ktlint/0.50.0/install/integrations/#custom-gradle-integration

That worked for me.

@wakingrufus
Copy link
Collaborator

Looks like my implementations for ktlint 0.49 and 0.50 don't properly load custom rulesets from the classpath. This was reported in #697 as well. I will work on a fix

@wakingrufus wakingrufus self-assigned this Aug 3, 2023
wakingrufus added a commit that referenced this issue Aug 7, 2023
fixes #697 and #695

test custom rule loading in ktlin 0.50.0 by updating sample project

To Test: Edit Main.kt in the kotlin-rulesets-using projects according to inline comment, then
run ./gradlew samples:kotlin-rulesets-using:build
wakingrufus added a commit that referenced this issue Aug 7, 2023
fixes #697 and #695

test custom rule loading in ktlin 0.50.0 by updating sample project

To Test: Edit Main.kt in the kotlin-rulesets-using projects according to inline comment, then
run ./gradlew samples:kotlin-rulesets-using:build

update root kotlin version to 1.8 since ktlint requires this
update android plugin to 4.1.3
wakingrufus added a commit that referenced this issue Aug 7, 2023
fixes #697 and #695

test custom rule loading in ktlin 0.50.0 by updating sample project

To Test: Edit Main.kt in the kotlin-rulesets-using projects according to inline comment, then
run ./gradlew samples:kotlin-rulesets-using:build

update root kotlin version to 1.8 since ktlint requires this
update android plugin to 4.1.3
@wakingrufus
Copy link
Collaborator

This should be fixed in 11.5.1. Please try again

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

3 participants