rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

RemoveRedundantDependencyVersions - too strict on scope matching

Open nmck257 opened this issue 3 years ago • 0 comments

Test case below -- RemoveRedundantDependencyVersions only touches a dependency if it has exactly the same scope as the managed dependency, but in actuality, there are valid cases where the scopes can mismatch and the managed version will still apply.

class MyTest : RewriteTest {
    @Test
    fun `should affect dependencies with test scope when managed dependency is default scope`() = rewriteRun(
        { spec -> spec.recipe(RemoveRedundantDependencyVersions(null, null, null)) },
        pomXml("""
            <?xml version="1.0" encoding="UTF-8"?>
            <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
                <modelVersion>4.0.0</modelVersion>
                <groupId>com.sample</groupId>
                <artifactId>my-project</artifactId>
                <version>1.0-SNAPSHOT</version>
                
                <parent>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-parent</artifactId>
                    <version>2.7.0</version>
                </parent>
                
                <dependencies>
                    <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-test</artifactId>
                        <version>2.7.0</version>
                        <scope>test</scope>
                    </dependency>
                </dependencies>
            </project>
        """, """
            <?xml version="1.0" encoding="UTF-8"?>
            <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
                <modelVersion>4.0.0</modelVersion>
                <groupId>com.sample</groupId>
                <artifactId>my-project</artifactId>
                <version>1.0-SNAPSHOT</version>
                
                <parent>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-parent</artifactId>
                    <version>2.7.0</version>
                </parent>
                
                <dependencies>
                    <dependency>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-test</artifactId>
                        <scope>test</scope>
                    </dependency>
                </dependencies>
            </project>
        """)) // failure -- recipe makes no change
}

nmck257 avatar Aug 09 '22 19:08 nmck257