openrewrite / rewrite-gradle-plugin

OpenRewrite's Gradle plugin.
Apache License 2.0
64 stars 40 forks source link

Compilation errors in netflix zuul #32

Closed gadams00 closed 3 years ago

gadams00 commented 3 years ago

When running rewrite-testing-frameworks against netflix zuul via rewrite-gradle-plugin gw rewriteRun, the recipes make modifications to multiple source files, and then a compile is run with many errors due to the fact that we don't currently have a way to change the junit dependencies in build.gradle. As far as I can tell, the rewriteRun task should not be running a compile. This may be due to some gradle configuration in netflix zuul, or perhaps something in the rewrite gradle plugin is running a build after rewriteRun. Investigate, and If it's the latter, prevent rewriteRun from running compile.

aegershman commented 3 years ago

I'm under the impression these are the lines of code which link compile and rewriteRun:

https://github.com/openrewrite/rewrite-gradle-plugin/blob/690bf81cce27a8098b0e40127411125b252c6edb/plugin/src/main/java/org/openrewrite/gradle/RewritePlugin.java#L96-L98

I tested netflix zuul by changing the build.gradle to look like this:

plugins {
    id 'nebula.netflixoss' version '9.1.0'
 ...
    id "org.openrewrite.rewrite" version "4.3.0"
}

...
subprojects {
    apply plugin: 'nebula.netflixoss'
...
    apply plugin: 'org.openrewrite.rewrite'
    dependencies {
        rewrite 'org.openrewrite.recipe:rewrite-testing-frameworks:1.4.0'
    }
    rewrite {
        activeRecipe("org.openrewrite.java.testing.junit5.JUnit5BestPractices")
    }

rewriteRun did fail due to compilation errors with:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':zuul-core:compileTestJava'.
> Compilation failed; see the compiler error output for details.

I guess that brings up the question, then, of whether or not compile should be ran after rewriteRun. It seems like it may be there only for validation purposes, but perhaps not strictly necessary.

I removed the dependsOn code, and tested against zuul locally, and rewriteRun executed fine, BUT, it wasn't in a compilable state afterwards (as expected)

...
import static org.junit.jupiter.api.Assertions.assertTrue;
^
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: /Users/aegershman/projects/benchmarks-misc/zuul/zuul-core/src/test/java/com/netflix/netty/common/proxyprotocol/StripUntrustedProxyHeadersHandlerTest.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
100 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':zuul-core:compileTestJava'.
> Compilation failed; see the compiler error output for details.

This means this is a matter of whether compile should be a requirement