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

Configure configurations as resolvable non-consumable #571

Merged
merged 3 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,54 @@ 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")
tbroyer marked this conversation as resolved.
Show resolved Hide resolved
@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) {
Expand Down