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

Support using Gradle projects as the dependency inputs #1901

Open
Goooler opened this issue Nov 22, 2023 · 5 comments
Open

Support using Gradle projects as the dependency inputs #1901

Goooler opened this issue Nov 22, 2023 · 5 comments

Comments

@Goooler
Copy link
Member

Goooler commented Nov 22, 2023

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.

@Goooler
Copy link
Member Author

Goooler commented Nov 23, 2023

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?

@bgaudiosi
Copy link

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.

@RubixDev
Copy link

RubixDev commented Mar 3, 2024

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.

@Goooler
Copy link
Member Author

Goooler commented Mar 3, 2024

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();

@jisungbin
Copy link

@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.

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

Successfully merging a pull request may close this issue.

5 participants