From 63e505dc2c8b70e3b79565de155e0b0421fb0612 Mon Sep 17 00:00:00 2001 From: Thomas Broyer Date: Thu, 27 Jan 2022 15:38:48 +0100 Subject: [PATCH 1/3] Configure configurations as resolvable non-consumable Keeping the default of being consumable exposes them to variant-aware resolution when the project is depended upon from another project. Also configure the configurations as non-visible for similar reasons: those are specific to this project's build and there's no reason to consume them from another project. Fix #523 --- .../gradle/ktlint/Configurations.kt | 19 ++++++++ .../gradle/ktlint/KtlintPluginTest.kt | 45 +++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/Configurations.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/Configurations.kt index 2eacfa00..c7ea296a 100644 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/Configurations.kt +++ b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/Configurations.kt @@ -27,6 +27,10 @@ internal fun createKtlintConfiguration(target: Project, extension: KtlintExtensi description = KTLINT_CONFIGURATION_DESCRIPTION + isCanBeResolved = true + isCanBeConsumed = false + isVisible = false + // Starting from KtLint 0.41.0 version published artifact has two variants: "external" and "shadowed" attributes { it.attribute(Bundling.BUNDLING_ATTRIBUTE, target.objects.named(Bundling::class.java, Bundling.EXTERNAL)) @@ -51,6 +55,11 @@ internal fun createKtlintRulesetConfiguration( ): Configuration = target .configurations.maybeCreate(KTLINT_RULESET_CONFIGURATION_NAME).apply { description = KTLINT_RULESET_CONFIGURATION_DESCRIPTION + + isCanBeResolved = true + isCanBeConsumed = false + isVisible = false + ensureConsistencyWith(target, ktLintConfiguration) } @@ -63,6 +72,11 @@ internal fun createKtLintReporterConfiguration( .maybeCreate(KTLINT_REPORTER_CONFIGURATION_NAME) .apply { description = KTLINT_REPORTER_CONFIGURATION_DESCRIPTION + + isCanBeResolved = true + isCanBeConsumed = false + isVisible = false + ensureConsistencyWith(target, ktLintConfiguration) withDependencies { @@ -92,6 +106,11 @@ internal fun createKtLintBaselineReporterConfiguration( .maybeCreate(KTLINT_BASELINE_REPORTER_CONFIGURATION_NAME) .apply { description = KTLINT_BASELINE_REPORTER_CONFIGURATION_DESCRIPTION + + isCanBeResolved = true + isCanBeConsumed = false + isVisible = false + ensureConsistencyWith(target, ktLintConfiguration) withDependencies { diff --git a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt index 9e163fe7..ce8b660a 100644 --- a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt +++ b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt @@ -508,6 +508,51 @@ class KtlintPluginTest : AbstractPluginTest() { } } + @DisplayName("Should not leak KtLint as a variant into consuming projects") + @CommonTest + fun noLeakIntoConsumingProjects(gradleVersion: GradleVersion) { + project(gradleVersion) { + val producerDir = projectPath.resolve("producer").also { it.mkdirs() } + val consumerDir = projectPath.resolve("consumer").also { it.mkdirs() } + settingsGradle.appendText( + """ + + include ":producer" + include ":consumer" + """.trimIndent() + ) + + //language=Groovy + producerDir.buildFile().writeText( + """ + plugins { + id "org.jlleitschuh.gradle.ktlint" + } + configurations.create('default') + artifacts { + add('default', buildFile) + } + """.trimIndent() + ) + + //language=Groovy + consumerDir.buildFile().writeText( + """ + plugins { + id 'java' + } + dependencies { + implementation project(':producer') + } + """.trimIndent() + ) + + build(":consumer:dependencies") { + assertThat(output).doesNotContain("com.pinterest:ktlint") + } + } + } + @DisplayName("Should print paths to the generated reports on code style violations") @CommonTest fun printReportsPaths(gradleVersion: GradleVersion) { From e061db39d0c98612dfaa972b33530abfa518ddde Mon Sep 17 00:00:00 2001 From: Thomas Broyer Date: Fri, 28 Jan 2022 11:26:48 +0100 Subject: [PATCH 2/3] Add link to issue comment to the test's kdoc Co-authored-by: Jonathan Leitschuh --- .../kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt index ce8b660a..4746d81c 100644 --- a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt +++ b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt @@ -508,6 +508,9 @@ class KtlintPluginTest : AbstractPluginTest() { } } + /** + * See: https://github.com/JLLeitschuh/ktlint-gradle/issues/523#issuecomment-1022522032 + */ @DisplayName("Should not leak KtLint as a variant into consuming projects") @CommonTest fun noLeakIntoConsumingProjects(gradleVersion: GradleVersion) { From 64ac251ed06b3ac5347c13ab3ab061f06a8ad2d5 Mon Sep 17 00:00:00 2001 From: Thomas Broyer Date: Fri, 28 Jan 2022 11:30:52 +0100 Subject: [PATCH 3/3] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa468312..1a9fbdf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/). ### Fixed - Fix install hook action when git `hooks` folder doesn't exist [issue: #557](https://github.com/JLLeitschuh/ktlint-gradle/issues/557), [#563](https://github.com/JLLeitschuh/ktlint-gradle/pull/563) + - Fix some resolution issues when a project using the plugin in some specific setups is depended upon by another project [issue: #523](https://github.com/JLLeitschuh/ktlint-gradle/issues/523), [#571](https://github.com/JLLeitschuh/ktlint-gradle/pull/571) ### Removed - ?