@@ -404,6 +404,87 @@ internal class KotlinBuildScriptDependenciesRewriterTest {
404404 )
405405 }
406406
407+ @Test fun `only removes dependencies on expected configuration` () {
408+ // Given
409+ val sourceFile = dir.resolve(" build.gradle.kts" )
410+ sourceFile.writeText(
411+ """
412+ plugins {
413+ id("foo")
414+ }
415+
416+ repositories {
417+ google()
418+ mavenCentral()
419+ }
420+
421+ apply(plugin = "bar")
422+
423+ extra["magic"] = 42
424+
425+ android {
426+ whatever
427+ }
428+
429+ dependencies {
430+ implementation("heart:of-gold:1.+")
431+ api(project(":marvin"))
432+ testImplementation("pan-galactic:gargle-blaster:2.0-SNAPSHOT") {
433+ because("life's too short not to")
434+ }
435+ }
436+
437+ println("hello, world!")
438+ """ .trimIndent()
439+ )
440+ val advice = setOf (
441+ Advice .ofChange(Coordinates .of(" :marvin" ), " api" , " compileOnly" ),
442+ Advice .ofRemove(Coordinates .of(" pan-galactic:gargle-blaster:2.0-SNAPSHOT" ), " implementation" ),
443+ Advice .ofAdd(Coordinates .of(" :sad-robot" ), " runtimeOnly" ),
444+ )
445+
446+ // When
447+ val parser = KotlinBuildScriptDependenciesRewriter .of(
448+ sourceFile,
449+ advice,
450+ AdvicePrinter (DslKind .KOTLIN ),
451+ )
452+
453+ println (parser.rewritten().trimmedLines())
454+ // Then
455+ assertThat(parser.rewritten().trimmedLines()).containsExactlyElementsIn(
456+ """
457+ plugins {
458+ id("foo")
459+ }
460+
461+ repositories {
462+ google()
463+ mavenCentral()
464+ }
465+
466+ apply(plugin = "bar")
467+
468+ extra["magic"] = 42
469+
470+ android {
471+ whatever
472+ }
473+
474+ dependencies {
475+ implementation("heart:of-gold:1.+")
476+ compileOnly(project(":marvin"))
477+ runtimeOnly(project(":sad-robot"))
478+ testImplementation("pan-galactic:gargle-blaster:2.0-SNAPSHOT") {
479+ because("life's too short not to")
480+ }
481+ }
482+
483+ println("hello, world!")
484+ """ .trimIndent().trimmedLines()
485+ )
486+ }
487+
407488 private fun Path.writeText (text : String ): Path = Files .writeString(this , text)
408489 private fun String.trimmedLines () = lines().map { it.trimEnd() }
409490}
0 commit comments