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 build agnostic external plugin SPI with dynamic lookups #2288

Open
kwin opened this issue Oct 2, 2024 · 1 comment
Open

Support build agnostic external plugin SPI with dynamic lookups #2288

kwin opened this issue Oct 2, 2024 · 1 comment

Comments

@kwin
Copy link
Contributor

kwin commented Oct 2, 2024

Currently adding a custom plugin requires adaptations to the Maven/Gradle plugin as
a) FormatterStepFactory and
b) FormatterFactory or FormatExtension

are
a) not build system agnostic and
b) are not dynamically looked up

It would be beneficial to have a build-agnostic plugin SPI which allows to
a) load dependencies
b) pass configuration
c) dynamically lookup services from classpath (e.g. with https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/ServiceLoader.html)

For Maven the mechanism for adding additional classes to the plugin classpath is via plugin dependencies. I hope that Gradle provides something similar.

@nedtwigg
Copy link
Member

nedtwigg commented Oct 2, 2024

For Gradle, you can just create a FormatterStep and add it.

public void addStep(FormatterStep newStep) {
requireNonNull(newStep);
int existingIdx = getExistingStepIdx(newStep.getName());
if (existingIdx != -1) {
throw new GradleException(
"Multiple steps with name '" + newStep.getName() + "' for spotless format '" + formatName() + "'");
}
steps.add(newStep);
}

For Maven, the problem is the DSL. How do you configure which targets the new step applies to? Happy to take a design and then PR for a plugin SPI, but it should be maven only. I recommend writing the docs first.

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

No branches or pull requests

2 participants