openrewrite / rewrite-docs

Stores the markdown documents used to generate docs.openrewrite.org
https://docs.openrewrite.org
Apache License 2.0
39 stars 42 forks source link

Compilation errors on "Running Rewrite without build tool plugins" #244

Closed timtebeek closed 8 months ago

timtebeek commented 8 months ago

As reported on https://stackoverflow.com/questions/77460250/how-to-get-openrewrite-running-without-build-tool-plugins-i-e-standalone

The description at "Running Rewrite without build tool plugins" suggests that OpenRewrite can be run on any Java project without requiring that project being a Maven or Gradle project. However, I could not manage to get the described class `RunRewriteManually` to compile properly.

When building "as is" I get

.../src/main/java/com/wamas/core/rewrite/Rewrite.java:49: error: incompatible types: Stream<SourceFile> cannot be converted to List<CompilationUnit>
        List<J.CompilationUnit> cus = javaParser.parse(sourcePaths, projectDir, ctx);
                                                      ^
.../src/main/java/com/wamas/core/rewrite/Rewrite.java:53: error: incompatible types: List<CompilationUnit> cannot be converted to LargeSourceSet
        List<Result> results = recipe.run(cus, ctx).getResults();
                                          ^

Adding `.collect(Collectors.toList()` to the first statement doesn't improve it because the types don't match:

/src/main/java/com/wamas/core/rewrite/Rewrite.java:50: error: incompatible types: inference variable T has incompatible bounds
        List<J.CompilationUnit> cus = javaParser.parse(sourcePaths, projectDir, ctx).collect(Collectors.toList());
                                                                                            ^
    equality constraints: CompilationUnit
    lower bounds: SourceFile
  where T is a type-variable:
    T extends Object declared in method <T>toList()

This second case is more a Java than an OpenRewrite problem, but I just don't get the error cause.
timtebeek commented 8 months ago

Picked up in

As indicated there we recommend folks use the Moderne CLI, especially when they do not use Maven nor Gradle.