Skip to content

Support using Gradle projects as the dependency inputs #1901

Open

Description

@Goooler

I'd finished Ktlint custom rule sets support in #1896, but it supports Maven coordinates only due to the limits of

/** Provisions the given maven coordinates and their transitive dependencies. */
public static JarState from(Collection<String> mavenCoordinates, Provisioner provisioner) throws IOException {
return provisionWithTransitives(true, mavenCoordinates, provisioner);
}

We can extend this for Gradle local projects to be used as the inputs, not sure if this way works for Maven projects as well.

Activity

  1. Goooler commented on Nov 23, 2023

    @Goooler
    MemberAuthor

    Another workable way is using spotless configuration like

    dependencies {
      spotless("org.junit.jupiter:junit-jupiter:5.10.0")
      spotless(libs.jupiter)
      spotless(projects.b)
      ...
    }

    I guess this is an intended behavior of not using it?

  2. bgaudiosi commented on Jan 12, 2024

    @bgaudiosi

    I'm running into this as well. I've created a new rule in the same (gradle) project that I'd like to apply it which doesn't seem possible at the moment.

  3. RubixDev commented on Mar 3, 2024

    @RubixDev

    Another workable way is using spotless configuration like

    dependencies {
      spotless("org.junit.jupiter:junit-jupiter:5.10.0")
      spotless(libs.jupiter)
      spotless(projects.b)
      ...
    }

    I guess this is an intended behavior of not using it?

    Are you saying there already is such a spotless configuration and it's already possible to use Gradle projects as dependencies? Because if you are, it's not working for me. And I would really like to have this feature.

  4. Goooler commented on Mar 3, 2024

    @Goooler
    MemberAuthor

    Not yet, it's a proposal. There are some issues related to reuse configurations:

    Configuration config = configurations.create("spotless"
    + new Request(withTransitives, mavenCoords).hashCode());
    mavenCoords.stream()
    .map(dependencies::create)
    .forEach(config.getDependencies()::add);
    config.setDescription(mavenCoords.toString());
    config.setTransitive(withTransitives);
    config.setCanBeConsumed(false);
    config.setVisible(false);
    config.attributes(attr -> {
    attr.attribute(Category.CATEGORY_ATTRIBUTE, project.getObjects().named(Category.class, Category.LIBRARY));
    attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL));
    // TODO: This is a copy-paste from org.gradle.api.attributes.java.TargetJvmEnvironment which is added in Gradle 7.0, remove this once we drop support for Gradle 6.x.
    // Add this attribute for resolving Guava dependency, see https://github.com/google/guava/issues/6801.
    attr.attribute(Attribute.of("org.gradle.jvm.environment", String.class), "standard-jvm");
    });
    return config.resolve();

  5. jisungbin commented on Jul 5, 2024

    @jisungbin

    @bgaudiosi I'm running into this as well. I've created a new rule in the same (gradle) project that I'd like to apply it which doesn't seem possible at the moment.

    I solved this problem by releasing a custom ruleset module to MavenLocal and using it.

  6. ntkoopman commented on Jun 5, 2025

    @ntkoopman

    It would be great to have a better solution, but as a workaround you can set up a substitution rule in Gradle:

    configurations.all {
        resolutionStrategy.dependencySubstitution {
            substitute(module("my:ktlint-rules")).using(project(":ktlint-rules"))
        }
    }
    
    tasks.withType(com.diffplug.gradle.spotless.SpotlessTask::class) {
        dependsOn(":ktlint-rules:jar")
    }
    
    spotless {
        kotlin {
            ktlint().customRuleSets(listOf("my:ktlint-rules:+"))
        }
    }
  7. Goooler commented on Jun 5, 2025

    @Goooler
    MemberAuthor

    Yeah, this is great!

  8. ntkoopman commented on Jul 20, 2026

    @ntkoopman

    Unfortunately, this has stopped working with spotless 8.5.0, since it switched to a detachedConfiguration, which is not configurable (4f9de0f) @bric3

  9. bric3 commented on Jul 21, 2026

    @bric3
    Contributor

    @ntkoopman Sorry I wasn't aware of this "hidden" feature.

    The move to detached configuration is a necessary move for Gradle 9. And making a detached configuration depending whether it's root project or not seems like a future thing to trip on.

    I'm experimenting right now, and I think that using the existing DSL is a better way to approach this. In particular I'm eying to make customRuleSet to be able to be passed a dependency notation, e.g.

    configure<SpotlessExtensionPredeclare> {
        kotlin {
            ktlint("1.0.1").customRuleSets(project(":ktlint-rules"))
        }
    }

    So no need to mess with the configurations, so less possible errors.


    The following idea can't work today in spotless since there can be multiple tool ; each tool should be somewhat having their own configuration, so a named spotless can't do that. If each requested tool had their own configuration, how to name them automatically, this looks like a point of friction (among others).

    dependencies {
      spotless("org.junit.jupiter:junit-jupiter:5.10.0")
      spotless(libs.jupiter)
      spotless(projects.b)
      ...
    }
    

    As of today, I think only ktlint can consume other artifacts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions