How to get OpenRewrite running without build tool plugins (i.e. standalone)

324 Views Asked by At

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.

0

There are 0 best solutions below