Repository navigation
Description
palantir-java-format is a modern, lambda-friendly, 120 character Java formatter based on the excellent google-java-format, and benefits from the work of all the original authors. palantir-java-format is available under the same (Apache 2.0 License)[https://github.com/palantir/palantir-java-format/blob/develop/LICENSE].
Examples from the readme
(1) before:
private static void configureResolvedVersionsWithVersionMapping(Project project) {
project.getPluginManager()
.withPlugin(
"maven-publish",
plugin -> {
project.getExtensions()
.getByType(PublishingExtension.class)
.getPublications()
.withType(MavenPublication.class)
.configureEach(
publication ->
publication.versionMapping(
mapping -> {
mapping.allVariants(
VariantVersionMappingStrategy
::fromResolutionResult);
}));
});
}(1) after:
private static void configureResolvedVersionsWithVersionMapping(Project project) {
project.getPluginManager().withPlugin("maven-publish", plugin -> {
project.getExtensions()
.getByType(PublishingExtension.class)
.getPublications()
.withType(MavenPublication.class)
.configureEach(publication -> publication.versionMapping(mapping -> {
mapping.allVariants(VariantVersionMappingStrategy::fromResolutionResult);
}));
});
}(2) before:
private static GradleException notFound(
String group, String name, Configuration configuration) {
String actual =
configuration.getIncoming().getResolutionResult().getAllComponents().stream()
.map(ResolvedComponentResult::getModuleVersion)
.map(
mvi ->
String.format(
"\t- %s:%s:%s",
mvi.getGroup(), mvi.getName(), mvi.getVersion()))
.collect(Collectors.joining("\n"));
// ...
}(2) after:
private static GradleException notFound(String group, String name, Configuration configuration) {
String actual = configuration.getIncoming().getResolutionResult().getAllComponents().stream()
.map(ResolvedComponentResult::getModuleVersion)
.map(mvi -> String.format("\t- %s:%s:%s", mvi.getGroup(), mvi.getName(), mvi.getVersion()))
.collect(Collectors.joining("\n"));
// ...
}We've leveraged the expanded configuration surface of the Gradle plugin to use a custom spotless format step with Gradle, however it's not quite as easy to wire in using the maven plugin. I'd love to use spotless with the Palantir java formatter in some maven projects, but it's nontrivial to wire together externally. Rather than attempting to rebuild your excellent wheel, I'd like to investigate if there's any interest in accepting it as a third java formatter option out of the box.
Thanks!
Activity
nedtwigg commentedon Jan 10, 2022
Tons of interest! The best way is probably to add a
PalantirJavaFormatSteplike this.If your API is close enough to GoogleJavaFormat's, then another way to do it is to add a configuration option to the existing GoogleJavaFormatStep, but I imagine that even if your API's match today, they might diverge over time, so probably best to stay decoupled.
A recent PR which I would consider a canonical example of adding a new formatter is #1011.
[-]Would you accept a contribution to support 'palantir-java-format'?[/-][+]Add support for 'palantir-java-format'[/+]carterkozak commentedon Jan 10, 2022
Fantastic, thanks @nedtwigg! I'll put together a PR this evening :-)
fix diffplug#1076: Add support for palantir-java-format
Add support for palantir-java-format (#1083 implements #1076)
nedtwigg commentedon Jan 13, 2022
Released in
plugin-gradle 6.2.0andplugin-maven 2.20.0.