From 0948c3e2323895efc7d6574d5e20f9ce358d8708 Mon Sep 17 00:00:00 2001 From: Goooler Date: Fri, 8 Sep 2023 16:12:10 +0800 Subject: [PATCH 1/5] Support ktlint 1.0.0 https://github.com/pinterest/ktlint/releases/tag/1.0.0 --- lib/build.gradle | 7 +- .../compat/KtLintCompat1Dot0Dot0Adapter.java | 165 ++++++++++++++++++ .../glue/ktlint/KtlintFormatterFunc.java | 36 ++-- .../diffplug/spotless/kotlin/KtLintStep.java | 9 +- .../KtLintCompat1Dot0Dot0AdapterTest.java | 71 ++++++++ .../resources/EmptyClassBody.kt | 3 + .../resources/FailsNoSemicolons.kt | 3 + plugin-gradle/README.md | 2 +- .../spotless/maven/kotlin/KtlintTest.java | 10 +- .../spotless/kotlin/KtLintStepTest.java | 10 ++ 10 files changed, 293 insertions(+), 23 deletions(-) create mode 100644 lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java create mode 100644 lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java create mode 100644 lib/src/testCompatKtLint1Dot0Dot0/resources/EmptyClassBody.kt create mode 100644 lib/src/testCompatKtLint1Dot0Dot0/resources/FailsNoSemicolons.kt diff --git a/lib/build.gradle b/lib/build.gradle index 01591e557d..0288277c78 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -48,6 +48,7 @@ versionCompatibility { '0.48.0', '0.49.0', '0.50.0', + '1.0.0', ] targetSourceSetName = 'ktlint' } @@ -104,10 +105,14 @@ dependencies { compatKtLint0Dot49Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-rule-engine:0.49.0' compatKtLint0Dot49Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.49.0' compatKtLint0Dot49Dot0CompileAndTestOnly 'org.slf4j:slf4j-api:2.0.0' - // ktlint latest supported version + // ktlint previous supported version compatKtLint0Dot50Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-rule-engine:0.50.0' compatKtLint0Dot50Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:0.50.0' compatKtLint0Dot50Dot0CompileAndTestOnly 'org.slf4j:slf4j-api:2.0.0' + // ktlint latest supported version + compatKtLint1Dot0Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-rule-engine:1.0.0' + compatKtLint1Dot0Dot0CompileAndTestOnly 'com.pinterest.ktlint:ktlint-ruleset-standard:1.0.0' + compatKtLint1Dot0Dot0CompileAndTestOnly 'org.slf4j:slf4j-api:2.0.0' // palantirJavaFormat palantirJavaFormatCompileOnly 'com.palantir.javaformat:palantir-java-format:1.1.0' // this version needs to stay compilable against Java 8 for CI Job testNpm // scalafmt diff --git a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java new file mode 100644 index 0000000000..7b12169400 --- /dev/null +++ b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java @@ -0,0 +1,165 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.ktlint.compat; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.ServiceLoader; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.pinterest.ktlint.cli.ruleset.core.api.RuleSetProviderV3; +import com.pinterest.ktlint.rule.engine.api.Code; +import com.pinterest.ktlint.rule.engine.api.EditorConfigDefaults; +import com.pinterest.ktlint.rule.engine.api.EditorConfigOverride; +import com.pinterest.ktlint.rule.engine.api.KtLintRuleEngine; +import com.pinterest.ktlint.rule.engine.api.LintError; +import com.pinterest.ktlint.rule.engine.core.api.Rule; +import com.pinterest.ktlint.rule.engine.core.api.RuleId; +import com.pinterest.ktlint.rule.engine.core.api.RuleProvider; +import com.pinterest.ktlint.rule.engine.core.api.RuleSetId; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.CodeStyleEditorConfigPropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EditorConfigProperty; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.EndOfLinePropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.IndentSizeEditorConfigPropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.IndentStyleEditorConfigPropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.InsertFinalNewLineEditorConfigPropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.MaxLineLengthEditorConfigPropertyKt; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.RuleExecution; +import com.pinterest.ktlint.rule.engine.core.api.editorconfig.RuleExecutionEditorConfigPropertyKt; + +import kotlin.Pair; +import kotlin.Unit; +import kotlin.jvm.functions.Function2; + +public class KtLintCompat1Dot0Dot0Adapter implements KtLintCompatAdapter { + + private static final Logger logger = LoggerFactory.getLogger(KtLintCompat1Dot0Dot0Adapter.class); + + private static final List> DEFAULT_EDITOR_CONFIG_PROPERTIES; + + static { + List> list = new ArrayList<>(); + list.add(CodeStyleEditorConfigPropertyKt.getCODE_STYLE_PROPERTY()); + list.add(EndOfLinePropertyKt.getEND_OF_LINE_PROPERTY()); + list.add(IndentSizeEditorConfigPropertyKt.getINDENT_SIZE_PROPERTY()); + list.add(IndentStyleEditorConfigPropertyKt.getINDENT_STYLE_PROPERTY()); + list.add(InsertFinalNewLineEditorConfigPropertyKt.getINSERT_FINAL_NEWLINE_PROPERTY()); + list.add(MaxLineLengthEditorConfigPropertyKt.getMAX_LINE_LENGTH_PROPERTY()); + list.add(RuleExecutionEditorConfigPropertyKt.getEXPERIMENTAL_RULES_EXECUTION_PROPERTY()); + DEFAULT_EDITOR_CONFIG_PROPERTIES = Collections.unmodifiableList(list); + } + + static class FormatterCallback implements Function2 { + + @Override + public Unit invoke(LintError lint, Boolean corrected) { + if (!corrected) { + KtLintCompatReporting.report(lint.getLine(), lint.getCol(), lint.getRuleId().getValue(), lint.getDetail()); + } + return Unit.INSTANCE; + } + } + + @Override + public String format(final String text, Path path, final boolean isScript, + Path editorConfigPath, final Map userData, + final Map editorConfigOverrideMap) { + final FormatterCallback formatterCallback = new FormatterCallback(); + + Set allRuleProviders = ServiceLoader.load(RuleSetProviderV3.class, RuleSetProviderV3.class.getClassLoader()) + .stream() + .flatMap(loader -> loader.get().getRuleProviders().stream()) + .collect(Collectors.toUnmodifiableSet()); + + EditorConfigOverride editorConfigOverride; + if (editorConfigOverrideMap.isEmpty()) { + editorConfigOverride = EditorConfigOverride.Companion.getEMPTY_EDITOR_CONFIG_OVERRIDE(); + } else { + editorConfigOverride = createEditorConfigOverride(allRuleProviders.stream().map( + RuleProvider::createNewRuleInstance).collect(Collectors.toList()), + editorConfigOverrideMap); + } + EditorConfigDefaults editorConfig; + if (editorConfigPath == null || !Files.exists(editorConfigPath)) { + editorConfig = EditorConfigDefaults.Companion.getEMPTY_EDITOR_CONFIG_DEFAULTS(); + } else { + editorConfig = EditorConfigDefaults.Companion.load(editorConfigPath, Collections.emptySet()); + } + + return new KtLintRuleEngine( + allRuleProviders, + editorConfig, + editorConfigOverride, + false, + path.getFileSystem()) + .format(Code.Companion.fromPath(path), formatterCallback); + } + + /** + * Create EditorConfigOverride from user provided parameters. + */ + private static EditorConfigOverride createEditorConfigOverride(final List rules, Map editorConfigOverrideMap) { + // Get properties from rules in the rule sets + Stream> ruleProperties = rules.stream() + .flatMap(rule -> rule.getUsesEditorConfigProperties().stream()); + + // Create a mapping of properties to their names based on rule properties and default properties + Map> supportedProperties = Stream + .concat(ruleProperties, DEFAULT_EDITOR_CONFIG_PROPERTIES.stream()) + .distinct() + .collect(Collectors.toMap(EditorConfigProperty::getName, property -> property)); + + // Create config properties based on provided property names and values + @SuppressWarnings("unchecked") + Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() + .map(entry -> { + EditorConfigProperty property = supportedProperties.get(entry.getKey()); + + if (property == null && entry.getKey().startsWith("ktlint_")) { + String[] parts = entry.getKey().substring(7).split("_", 2); + if (parts.length == 1) { + // convert ktlint_{ruleset} to RuleSetId + RuleSetId id = new RuleSetId(parts[0]); + property = RuleExecutionEditorConfigPropertyKt.createRuleSetExecutionEditorConfigProperty(id, RuleExecution.enabled); + } else { + // convert ktlint_{ruleset}_{rulename} to RuleId + RuleId id = new RuleId(parts[0] + ":" + parts[1]); + property = RuleExecutionEditorConfigPropertyKt.createRuleExecutionEditorConfigProperty(id, RuleExecution.enabled); + } + } + + if (property == null) { + return null; + } else { + return new Pair<>(property, entry.getValue()); + } + }) + .filter(Objects::nonNull) + .toArray(Pair[]::new); + + return EditorConfigOverride.Companion.from(properties); + } +} diff --git a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java index 1a11e8bcce..7ae0222566 100644 --- a/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java +++ b/lib/src/ktlint/java/com/diffplug/spotless/glue/ktlint/KtlintFormatterFunc.java @@ -33,22 +33,28 @@ public class KtlintFormatterFunc implements FormatterFunc.NeedsFile { public KtlintFormatterFunc(String version, boolean isScript, FileSignature editorConfigPath, Map userData, Map editorConfigOverrideMap) { - int minorVersion = Integer.parseInt(version.split("\\.")[1]); - if (minorVersion >= 50) { - // Fixed `RuleId` and `RuleSetId` issues - // New argument to `EditorConfigDefaults.Companion.load(...)` for custom property type parsing - // New argument to `new KtLintRuleEngine(...)` to fail on usage of `treeCopyHandler` extension point - this.adapter = new KtLintCompat0Dot50Dot0Adapter(); - } else if (minorVersion == 49) { - // Packages and modules moved around (`ktlint-core` -> `ktlint-rule-engine`) - // Experimental ruleset was replaced by implementing `Rule.Experimental` and checking the `ktlint_experimental` `.editorconfig` property - // `RuleId` and `RuleSetId` became inline classes (mangled to be unrepresentable in Java source code, so reflection is needed), tracked here: https://github.com/pinterest/ktlint/issues/2041 - this.adapter = new KtLintCompat0Dot49Dot0Adapter(); - } else if (minorVersion == 48) { - // ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class - this.adapter = new KtLintCompat0Dot48Dot0Adapter(); + String[] versions = version.split("\\."); + int majorVersion = Integer.parseInt(versions[0]); + int minorVersion = Integer.parseInt(versions[1]); + if (majorVersion == 1) { + this.adapter = new KtLintCompat1Dot0Dot0Adapter(); } else { - throw new IllegalStateException("Ktlint versions < 0.48.0 not supported!"); + if (minorVersion >= 50) { + // Fixed `RuleId` and `RuleSetId` issues + // New argument to `EditorConfigDefaults.Companion.load(...)` for custom property type parsing + // New argument to `new KtLintRuleEngine(...)` to fail on usage of `treeCopyHandler` extension point + this.adapter = new KtLintCompat0Dot50Dot0Adapter(); + } else if (minorVersion == 49) { + // Packages and modules moved around (`ktlint-core` -> `ktlint-rule-engine`) + // Experimental ruleset was replaced by implementing `Rule.Experimental` and checking the `ktlint_experimental` `.editorconfig` property + // `RuleId` and `RuleSetId` became inline classes (mangled to be unrepresentable in Java source code, so reflection is needed), tracked here: https://github.com/pinterest/ktlint/issues/2041 + this.adapter = new KtLintCompat0Dot49Dot0Adapter(); + } else if (minorVersion == 48) { + // ExperimentalParams lost two constructor arguments, EditorConfigProperty moved to its own class + this.adapter = new KtLintCompat0Dot48Dot0Adapter(); + } else { + throw new IllegalStateException("Ktlint versions < 0.48.0 not supported!"); + } } this.editorConfigPath = editorConfigPath; this.editorConfigOverrideMap = editorConfigOverrideMap; diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index 8f3fde5731..d08c59b839 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -36,10 +36,10 @@ public class KtLintStep { // prevent direct instantiation private KtLintStep() {} - private static final String DEFAULT_VERSION = "0.50.0"; + private static final String DEFAULT_VERSION = "1.0.0"; static final String NAME = "ktlint"; - static final String PACKAGE = "com.pinterest"; - static final String MAVEN_COORDINATE = PACKAGE + ":ktlint:"; + static final String MAVEN_COORDINATE_0_DOT = "com.pinterest:ktlint:"; + static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:"; public static FormatterStep create(Provisioner provisioner) { return create(defaultVersion(), provisioner); @@ -110,7 +110,8 @@ static final class State implements Serializable { this.version = version; this.userData = new TreeMap<>(userData); this.editorConfigOverride = new TreeMap<>(editorConfigOverride); - this.jarState = JarState.from(MAVEN_COORDINATE + version, provisioner); + this.jarState = JarState.from((version.startsWith("0.") ? MAVEN_COORDINATE_0_DOT : MAVEN_COORDINATE_1_DOT) + version, + provisioner); this.editorConfigPath = editorConfigPath; this.isScript = isScript; } diff --git a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java new file mode 100644 index 0000000000..5ed2517c6f --- /dev/null +++ b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java @@ -0,0 +1,71 @@ +/* + * Copyright 2023 DiffPlug + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.diffplug.spotless.glue.ktlint.compat; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +public class KtLintCompat1Dot0Dot0AdapterTest { + @Test + public void testDefaults(@TempDir Path path) throws IOException { + KtLintCompat1Dot0Dot0Adapter KtLintCompat1Dot0Dot0Adapter = new KtLintCompat1Dot0Dot0Adapter(); + String text = loadAndWriteText(path, "EmptyClassBody.kt"); + final Path filePath = Paths.get(path.toString(), "EmptyClassBody.kt"); + + Map userData = new HashMap<>(); + + Map editorConfigOverrideMap = new HashMap<>(); + + String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); + assertEquals("class EmptyClassBody\n", formatted); + } + + @Test + public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { + KtLintCompat1Dot0Dot0Adapter KtLintCompat1Dot0Dot0Adapter = new KtLintCompat1Dot0Dot0Adapter(); + String text = loadAndWriteText(path, "FailsNoSemicolons.kt"); + final Path filePath = Paths.get(path.toString(), "FailsNoSemicolons.kt"); + + Map userData = new HashMap<>(); + + Map editorConfigOverrideMap = new HashMap<>(); + editorConfigOverrideMap.put("indent_style", "tab"); + editorConfigOverrideMap.put("ktlint_code_style", "intellij_idea"); + editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); + + String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); + assertEquals("class FailsNoSemicolons {\n\tval i = 0;\n}\n", formatted); + } + + private static String loadAndWriteText(Path path, String name) throws IOException { + try (InputStream is = KtLintCompat1Dot0Dot0AdapterTest.class.getResourceAsStream("/" + name)) { + Files.copy(is, path.resolve(name)); + } + return new String(Files.readAllBytes(path.resolve(name)), StandardCharsets.UTF_8); + } + +} diff --git a/lib/src/testCompatKtLint1Dot0Dot0/resources/EmptyClassBody.kt b/lib/src/testCompatKtLint1Dot0Dot0/resources/EmptyClassBody.kt new file mode 100644 index 0000000000..7da53fb78d --- /dev/null +++ b/lib/src/testCompatKtLint1Dot0Dot0/resources/EmptyClassBody.kt @@ -0,0 +1,3 @@ +class EmptyClassBody { + +} diff --git a/lib/src/testCompatKtLint1Dot0Dot0/resources/FailsNoSemicolons.kt b/lib/src/testCompatKtLint1Dot0Dot0/resources/FailsNoSemicolons.kt new file mode 100644 index 0000000000..4cf05ceacf --- /dev/null +++ b/lib/src/testCompatKtLint1Dot0Dot0/resources/FailsNoSemicolons.kt @@ -0,0 +1,3 @@ +class FailsNoSemicolons { + val i = 0; +} diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 944c07bb6e..9cc5019f57 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -399,7 +399,7 @@ Additionally, `editorConfigOverride` options will override what's supplied in `. spotless { kotlin { // version, userData and editorConfigOverride are all optional - ktlint("0.50.0") + ktlint("1.0.0") .userData(mapOf("android" to "true")) .setEditorConfigPath("$projectDir/config/.editorconfig") // sample unusual placement .editorConfigOverride(mapOf("indent_size" to 2)) diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java index ba6f1d8e2c..f3f360dc5d 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,13 @@ void testKtlint() throws Exception { @Test void testKtlintEditorConfigOverride() throws Exception { - writePomWithKotlinSteps("truetrue"); + writePomWithKotlinSteps("\n" + + " \n" + + " true\n" + + " true\n" + + " intellij_idea\n" + + " \n" + + ""); String path = "src/main/kotlin/Main.kt"; setFile(path).toResource("kotlin/ktlint/experimentalEditorConfigOverride.dirty"); diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 5b62eeed48..0ccb47d1ed 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -74,6 +74,16 @@ void works0_50_0() { "Wildcard import"); } + @Test + void works1_0_0() { + FormatterStep step = KtLintStep.create("1.0.0", TestProvisioner.mavenCentral()); + StepHarnessWithFile.forStep(this, step) + .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") + .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + + "rule: standard:no-wildcard-imports\n" + + "Wildcard import"); + } + @Test void behavior() { FormatterStep step = KtLintStep.create(TestProvisioner.mavenCentral()); From 0224d3575f35e537f2cbc93e0903b984df389f44 Mon Sep 17 00:00:00 2001 From: Goooler Date: Sun, 10 Sep 2023 02:00:45 +0800 Subject: [PATCH 2/5] Update changelogs --- CHANGES.md | 2 ++ plugin-gradle/CHANGES.md | 3 +++ plugin-gradle/README.md | 7 ++++++- plugin-maven/CHANGES.md | 3 +++ plugin-maven/README.md | 3 ++- 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1d78e8d932..c2d379a874 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,8 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* **POTENTIALLY BREAKING** Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). ## [2.41.0] - 2023-08-29 ### Added diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index eab7e32b2d..b66fcbc262 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -3,6 +3,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `3.27.0`). ## [Unreleased] +### Added +* **POTENTIALLY BREAKING** Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). + The default code style had been changed to `ktlint_official`, if you are upgrading from the old versions, may need to override the style in `editorConfigOverride`. ## [6.21.0] - 2023-08-29 ### Added diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 9cc5019f57..9a4b84c4dd 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -402,7 +402,12 @@ spotless { ktlint("1.0.0") .userData(mapOf("android" to "true")) .setEditorConfigPath("$projectDir/config/.editorconfig") // sample unusual placement - .editorConfigOverride(mapOf("indent_size" to 2)) + .editorConfigOverride( + mapOf( + "indent_size" to 2, + "ktlint_code_style" to "intellij_idea", + ) + ) } } ``` diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index f932806fcc..54f92898a1 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -3,6 +3,9 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] +### Added +* **POTENTIALLY BREAKING** Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). +The default code style had been changed to `ktlint_official`, if you are upgrading from the old versions, may need to override the style in `editorConfigOverride`. ## [2.39.0] - 2023-08-29 ### Added diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 74872ef61f..9419490d3e 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -409,10 +409,11 @@ Additionally, `editorConfigOverride` options will override what's supplied in `. ```xml - 0.43.2 + 1.0.0 true true + intellij_idea ``` From 919b4811448e1ec11ceadfebc8bcfc8f48137ad4 Mon Sep 17 00:00:00 2001 From: Goooler Date: Fri, 15 Sep 2023 13:41:57 +0800 Subject: [PATCH 3/5] Fix ktlint tests --- .../com/diffplug/spotless/kotlin/KtLintStep.java | 2 +- .../diffplug/gradle/spotless/GradleProvisioner.java | 10 +++++++++- .../gradle/spotless/KotlinExtensionTest.java | 1 + .../gradle/spotless/KotlinGradleExtensionTest.java | 1 + .../java/com/diffplug/spotless/TestProvisioner.java | 12 ++++++++++-- .../com/diffplug/spotless/kotlin/KtLintStepTest.java | 8 ++++---- 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index d08c59b839..bedbb4a071 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -39,7 +39,7 @@ private KtLintStep() {} private static final String DEFAULT_VERSION = "1.0.0"; static final String NAME = "ktlint"; static final String MAVEN_COORDINATE_0_DOT = "com.pinterest:ktlint:"; - static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:"; + public static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:"; public static FormatterStep create(Provisioner provisioner) { return create(defaultVersion(), provisioner); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java index e1129b3b0b..a92d583596 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java @@ -34,6 +34,7 @@ import com.diffplug.common.base.Unhandled; import com.diffplug.common.collect.ImmutableList; import com.diffplug.spotless.Provisioner; +import com.diffplug.spotless.kotlin.KtLintStep; /** Should be package-private. */ class GradleProvisioner { @@ -121,7 +122,14 @@ private static Provisioner forConfigurationContainer(Project project, Configurat config.setCanBeConsumed(false); config.setVisible(false); config.attributes(attr -> { - attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL)); + final String type; + // See https://github.com/diffplug/spotless/pull/1808#discussion_r1321682984. + if (mavenCoords.stream().anyMatch(it -> it.startsWith(KtLintStep.MAVEN_COORDINATE_1_DOT))) { + type = Bundling.SHADOWED; + } else { + type = Bundling.EXTERNAL; + } + attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, type)); }); return config.resolve(); } catch (Exception e) { diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index 1c23728244..a2fa7c16e7 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -73,6 +73,7 @@ void withExperimentalEditorConfigOverride() throws IOException { "spotless {", " kotlin {", " ktlint().editorConfigOverride([", + " ktlint_code_style: \"intellij_idea\",", " ktlint_experimental: \"enabled\",", " ij_kotlin_allow_trailing_comma: true,", " ij_kotlin_allow_trailing_comma_on_call_site: true", diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java index 7dade5f2ff..6d7bdf351a 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java @@ -52,6 +52,7 @@ void withExperimentalEditorConfigOverride() throws IOException { "spotless {", " kotlinGradle {", " ktlint().editorConfigOverride([", + " ktlint_code_style: \"intellij_idea\",", " ktlint_experimental: \"enabled\",", " ij_kotlin_allow_trailing_comma: true,", " ij_kotlin_allow_trailing_comma_on_call_site: true", diff --git a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java index 0d9ced4c9e..6a942d8ca3 100644 --- a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java +++ b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 DiffPlug + * Copyright 2016-2023 DiffPlug * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,6 +39,7 @@ import com.diffplug.common.base.Suppliers; import com.diffplug.common.collect.ImmutableSet; import com.diffplug.common.io.Files; +import com.diffplug.spotless.kotlin.KtLintStep; public class TestProvisioner { public static Project gradleProject(File dir) { @@ -70,7 +71,14 @@ private static Provisioner createWithRepositories(Consumer re config.setTransitive(withTransitives); config.setDescription(mavenCoords.toString()); config.attributes(attr -> { - attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL)); + final String type; + // See https://github.com/diffplug/spotless/pull/1808#discussion_r1321682984. + if (mavenCoords.stream().anyMatch(it -> it.startsWith(KtLintStep.MAVEN_COORDINATE_1_DOT))) { + type = Bundling.SHADOWED; + } else { + type = Bundling.EXTERNAL; + } + attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, type)); }); try { return config.resolve(); diff --git a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java index 0ccb47d1ed..02526b46e6 100644 --- a/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java +++ b/testlib/src/test/java/com/diffplug/spotless/kotlin/KtLintStepTest.java @@ -80,8 +80,8 @@ void works1_0_0() { StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + - "rule: standard:no-wildcard-imports\n" + - "Wildcard import"); + "rule: standard:no-empty-file\n" + + "File 'unsolvable.dirty' should not be empty"); } @Test @@ -90,8 +90,8 @@ void behavior() { StepHarnessWithFile.forStep(this, step) .testResource("kotlin/ktlint/basic.dirty", "kotlin/ktlint/basic.clean") .testResourceExceptionMsg("kotlin/ktlint/unsolvable.dirty").isEqualTo("Error on line: 1, column: 1\n" + - "rule: standard:no-wildcard-imports\n" + - "Wildcard import"); + "rule: standard:no-empty-file\n" + + "File 'unsolvable.dirty' should not be empty"); } @Test From 7de7991d86f867ed7c528d915eec493c2699be25 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 19 Sep 2023 08:41:39 +0800 Subject: [PATCH 4/5] Compat old ktlint users --- CHANGES.md | 2 +- .../glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java | 5 +++++ .../glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java | 1 - plugin-gradle/CHANGES.md | 3 +-- plugin-gradle/README.md | 1 - .../com/diffplug/gradle/spotless/KotlinExtensionTest.java | 1 - .../diffplug/gradle/spotless/KotlinGradleExtensionTest.java | 1 - plugin-maven/CHANGES.md | 3 +-- plugin-maven/README.md | 1 - .../java/com/diffplug/spotless/maven/kotlin/KtlintTest.java | 1 - 10 files changed, 8 insertions(+), 11 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c2d379a874..4a831e9d0b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,7 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* **POTENTIALLY BREAKING** Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). +* Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). ## [2.41.0] - 2023-08-29 ### Added diff --git a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java index 7b12169400..9c2792f769 100644 --- a/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java +++ b/lib/src/compatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0Adapter.java @@ -132,6 +132,11 @@ private static EditorConfigOverride createEditorConfigOverride(final List .distinct() .collect(Collectors.toMap(EditorConfigProperty::getName, property -> property)); + // The default style had been changed from intellij_idea to ktlint_official in version 1.0.0 + if (!editorConfigOverrideMap.containsKey("ktlint_code_style")) { + editorConfigOverrideMap.put("ktlint_code_style", "intellij_idea"); + } + // Create config properties based on provided property names and values @SuppressWarnings("unchecked") Pair, ?>[] properties = editorConfigOverrideMap.entrySet().stream() diff --git a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java index 5ed2517c6f..1f8e6023b4 100644 --- a/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java +++ b/lib/src/testCompatKtLint1Dot0Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat1Dot0Dot0AdapterTest.java @@ -54,7 +54,6 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException { Map editorConfigOverrideMap = new HashMap<>(); editorConfigOverrideMap.put("indent_style", "tab"); - editorConfigOverrideMap.put("ktlint_code_style", "intellij_idea"); editorConfigOverrideMap.put("ktlint_standard_no-semi", "disabled"); String formatted = KtLintCompat1Dot0Dot0Adapter.format(text, filePath, false, null, userData, editorConfigOverrideMap); diff --git a/plugin-gradle/CHANGES.md b/plugin-gradle/CHANGES.md index b66fcbc262..feb5c67844 100644 --- a/plugin-gradle/CHANGES.md +++ b/plugin-gradle/CHANGES.md @@ -4,8 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* **POTENTIALLY BREAKING** Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). - The default code style had been changed to `ktlint_official`, if you are upgrading from the old versions, may need to override the style in `editorConfigOverride`. +* Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). ## [6.21.0] - 2023-08-29 ### Added diff --git a/plugin-gradle/README.md b/plugin-gradle/README.md index 9a4b84c4dd..03a94e5004 100644 --- a/plugin-gradle/README.md +++ b/plugin-gradle/README.md @@ -405,7 +405,6 @@ spotless { .editorConfigOverride( mapOf( "indent_size" to 2, - "ktlint_code_style" to "intellij_idea", ) ) } diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java index a2fa7c16e7..1c23728244 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinExtensionTest.java @@ -73,7 +73,6 @@ void withExperimentalEditorConfigOverride() throws IOException { "spotless {", " kotlin {", " ktlint().editorConfigOverride([", - " ktlint_code_style: \"intellij_idea\",", " ktlint_experimental: \"enabled\",", " ij_kotlin_allow_trailing_comma: true,", " ij_kotlin_allow_trailing_comma_on_call_site: true", diff --git a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java index 6d7bdf351a..7dade5f2ff 100644 --- a/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java +++ b/plugin-gradle/src/test/java/com/diffplug/gradle/spotless/KotlinGradleExtensionTest.java @@ -52,7 +52,6 @@ void withExperimentalEditorConfigOverride() throws IOException { "spotless {", " kotlinGradle {", " ktlint().editorConfigOverride([", - " ktlint_code_style: \"intellij_idea\",", " ktlint_experimental: \"enabled\",", " ij_kotlin_allow_trailing_comma: true,", " ij_kotlin_allow_trailing_comma_on_call_site: true", diff --git a/plugin-maven/CHANGES.md b/plugin-maven/CHANGES.md index 54f92898a1..ef310b3ea2 100644 --- a/plugin-maven/CHANGES.md +++ b/plugin-maven/CHANGES.md @@ -4,8 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format ( ## [Unreleased] ### Added -* **POTENTIALLY BREAKING** Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). -The default code style had been changed to `ktlint_official`, if you are upgrading from the old versions, may need to override the style in `editorConfigOverride`. +* Support Ktlint 1.0.0 ([#1808](https://github.com/diffplug/spotless/pull/1808)). ## [2.39.0] - 2023-08-29 ### Added diff --git a/plugin-maven/README.md b/plugin-maven/README.md index 9419490d3e..f63d7faed9 100644 --- a/plugin-maven/README.md +++ b/plugin-maven/README.md @@ -413,7 +413,6 @@ Additionally, `editorConfigOverride` options will override what's supplied in `. true true - intellij_idea ``` diff --git a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java index f3f360dc5d..060e0de84f 100644 --- a/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java +++ b/plugin-maven/src/test/java/com/diffplug/spotless/maven/kotlin/KtlintTest.java @@ -36,7 +36,6 @@ void testKtlintEditorConfigOverride() throws Exception { " \n" + " true\n" + " true\n" + - " intellij_idea\n" + " \n" + ""); From 4047ae01329491b1f3d79f4f792f842d9b526ea8 Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 19 Sep 2023 22:41:20 +0800 Subject: [PATCH 5/5] Add Category.LIBRARY attr to resolve ktlint deps --- .../com/diffplug/spotless/kotlin/KtLintStep.java | 2 +- .../diffplug/gradle/spotless/GradleProvisioner.java | 12 +++--------- .../java/com/diffplug/spotless/TestProvisioner.java | 12 +++--------- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java index bedbb4a071..d08c59b839 100644 --- a/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java +++ b/lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java @@ -39,7 +39,7 @@ private KtLintStep() {} private static final String DEFAULT_VERSION = "1.0.0"; static final String NAME = "ktlint"; static final String MAVEN_COORDINATE_0_DOT = "com.pinterest:ktlint:"; - public static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:"; + static final String MAVEN_COORDINATE_1_DOT = "com.pinterest.ktlint:ktlint-cli:"; public static FormatterStep create(Provisioner provisioner) { return create(defaultVersion(), provisioner); diff --git a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java index a92d583596..288cc10c72 100644 --- a/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java +++ b/plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GradleProvisioner.java @@ -27,6 +27,7 @@ import org.gradle.api.artifacts.ConfigurationContainer; import org.gradle.api.artifacts.dsl.DependencyHandler; import org.gradle.api.attributes.Bundling; +import org.gradle.api.attributes.Category; import org.gradle.api.initialization.dsl.ScriptHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +35,6 @@ import com.diffplug.common.base.Unhandled; import com.diffplug.common.collect.ImmutableList; import com.diffplug.spotless.Provisioner; -import com.diffplug.spotless.kotlin.KtLintStep; /** Should be package-private. */ class GradleProvisioner { @@ -122,14 +122,8 @@ private static Provisioner forConfigurationContainer(Project project, Configurat config.setCanBeConsumed(false); config.setVisible(false); config.attributes(attr -> { - final String type; - // See https://github.com/diffplug/spotless/pull/1808#discussion_r1321682984. - if (mavenCoords.stream().anyMatch(it -> it.startsWith(KtLintStep.MAVEN_COORDINATE_1_DOT))) { - type = Bundling.SHADOWED; - } else { - type = Bundling.EXTERNAL; - } - attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, type)); + attr.attribute(Category.CATEGORY_ATTRIBUTE, project.getObjects().named(Category.class, Category.LIBRARY)); + attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL)); }); return config.resolve(); } catch (Exception e) { diff --git a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java index 6a942d8ca3..e06640ccfd 100644 --- a/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java +++ b/testlib/src/main/java/com/diffplug/spotless/TestProvisioner.java @@ -32,6 +32,7 @@ import org.gradle.api.artifacts.ResolveException; import org.gradle.api.artifacts.dsl.RepositoryHandler; import org.gradle.api.attributes.Bundling; +import org.gradle.api.attributes.Category; import org.gradle.testfixtures.ProjectBuilder; import com.diffplug.common.base.Errors; @@ -39,7 +40,6 @@ import com.diffplug.common.base.Suppliers; import com.diffplug.common.collect.ImmutableSet; import com.diffplug.common.io.Files; -import com.diffplug.spotless.kotlin.KtLintStep; public class TestProvisioner { public static Project gradleProject(File dir) { @@ -71,14 +71,8 @@ private static Provisioner createWithRepositories(Consumer re config.setTransitive(withTransitives); config.setDescription(mavenCoords.toString()); config.attributes(attr -> { - final String type; - // See https://github.com/diffplug/spotless/pull/1808#discussion_r1321682984. - if (mavenCoords.stream().anyMatch(it -> it.startsWith(KtLintStep.MAVEN_COORDINATE_1_DOT))) { - type = Bundling.SHADOWED; - } else { - type = Bundling.EXTERNAL; - } - attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, type)); + attr.attribute(Category.CATEGORY_ATTRIBUTE, project.getObjects().named(Category.class, Category.LIBRARY)); + attr.attribute(Bundling.BUNDLING_ATTRIBUTE, project.getObjects().named(Bundling.class, Bundling.EXTERNAL)); }); try { return config.resolve();