Skip to content

Commit b9ffefa

Browse files
RBusarowkodiakhq[bot]
authored andcommitted
don't find must-be-api if the project is already an api dependency also
fixes #662
1 parent 1b3e912 commit b9ffefa

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

modulecheck-core/src/main/kotlin/modulecheck/core/context/MustBeApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ data class MustBeApi(
100100
.distinctBy { it.path }
101101
.filterNot { cpd ->
102102
// exclude anything which is inherited but already included in local `api` deps
103-
cpd in directApiProjects
103+
cpd.copy(configurationName = cpd.configurationName.apiVariant()) in directApiProjects
104104
}
105105
.filterAsync {
106106
!sourceSetName.isTestingOnly() && it.project(project.projectCache)

modulecheck-core/src/test/kotlin/modulecheck/core/MustBeApiTest.kt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,63 @@ class MustBeApiTest : RunnerTest() {
643643
logger.parsedReport() shouldBe listOf()
644644
}
645645

646+
@Test
647+
fun `api and implementation of the same dependency with auto-correct should not be changed`() {
648+
649+
val lib1 = kotlinProject(":lib1") {
650+
addKotlinSource(
651+
"""
652+
package com.modulecheck.lib1
653+
654+
class Lib1Class
655+
"""
656+
)
657+
}
658+
659+
val lib2 = kotlinProject(":lib2") {
660+
addDependency(ConfigurationName.api, lib1)
661+
addDependency(ConfigurationName.implementation, lib1)
662+
663+
buildFile {
664+
"""
665+
plugins {
666+
kotlin("jvm")
667+
}
668+
669+
dependencies {
670+
api(project(path = ":lib1"))
671+
implementation(project(path = ":lib1"))
672+
}
673+
"""
674+
}
675+
676+
addKotlinSource(
677+
"""
678+
package com.modulecheck.lib2
679+
680+
import com.modulecheck.lib1.Lib1Class
681+
682+
val lib1Class = Lib1Class()
683+
"""
684+
)
685+
}
686+
687+
run().isSuccess shouldBe true
688+
689+
lib2.buildFile shouldHaveText """
690+
plugins {
691+
kotlin("jvm")
692+
}
693+
694+
dependencies {
695+
api(project(path = ":lib1"))
696+
implementation(project(path = ":lib1"))
697+
}
698+
"""
699+
700+
logger.parsedReport() shouldBe listOf()
701+
}
702+
646703
@Test
647704
fun `public property from dependency in test source should not require API`() {
648705

0 commit comments

Comments
 (0)