openrewrite / rewrite-gradle-plugin

OpenRewrite's Gradle plugin.
Apache License 2.0
56 stars 34 forks source link

The Openrewrite plugin is making the sources configuration of the jvm-test-suite plugin not work #309

Open thaitangluc2412 opened 1 month ago

thaitangluc2412 commented 1 month ago

Description When I use the jvm-test-suite plugin simulation with OpenRewrite, the configuration of the testing suite sources does not work, so no tests can run.

Basic project Screenshot 2024-06-05 at 16 33 10

Screenshot 2024-06-05 at 16 42 11

build.gradle file

plugins {
    id 'jvm-test-suite'
    id 'java'
//    id 'org.openrewrite.rewrite' version "6.15.1"
}

dependencies {
    implementation 'org.junit.jupiter:junit-jupiter-api:5.10.2'
}

testing {
    suites {
        integrationTest(JvmTestSuite) {
            dependencies {
                implementation project()
            }
            sources {
                java {
                    srcDirs = ['src/test/java']
                }
                resources {
                    srcDirs = [ 'src/test/resources' ]
                }
            }

        }
    }
}

Steps to Reproduce

When I use two plugins, jvm-test-suite and java, and run integrationTest with the command ./gradlew integrationTest, it executes the test in the BasicTests class and shows the failed test results because the tests in BasicTests always fail. However, when I uncomment the OpenRewrite plugin in the build.gradle file and run the ./gradlew integrationTest command again, it does nothing and shows Build Successful, which means no tests were executed.

Screenshots

Screenshot 2024-06-05 at 16 52 17

Screenshot 2024-06-05 at 16 51 34

Environment

Openrewrite version: 6.15.1 Gradle version: 8.7 Java version: 17 junit-jupiter version: 5.10.2

Additional Context I downgraded the OpenRewrite version to 5.7.0, but the problem remains the same

timtebeek commented 1 month ago

Hi @thaitangluc2412 ; thanks for the detailed report; no idea what might go into that not working as expected. As a workaround you might be able to run rewrite recipes exclusively through an init script instead of adding the plugin to your build.gradle file.

shanman190 commented 1 month ago

What I suspect is the issue is this little block of code: https://github.com/openrewrite/rewrite-gradle-plugin/blob/main/plugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopenrewrite%2Fgradle%2FRewritePlugin.java#L122-L138

In particular, your test and integrationTest source sets are both pointing to the source folder src/test/java. If you were to run build, you should actually see your test run twice with each task based upon the configuration that you've shared here.

With the jvm-test-suite plugin, Gradle intends for you to use a different folder for each test suite (ie. src/integrationTest/java) normally. Due to the clash, the OpenRewrite plugin disabled the integration test compile task which then means the outputs from that are not available for the test task resulting in a successful build.

To expand upon Tim's earlier workaround, you either need to:

NOTE: I do find it a little weird that the OpenRewrite Gradle plugin is disabling other stuff during it's configuration phase. I know why it's doing it, but doing so results in weird issues such as this one.