How can I exclude files from being parsed by rewriteRun

678 Views Asked by At

I want to use the recipe AddOrUpdateAnnotationAttribute for adding parameters to a Java annotation. This is part of the package org.openrewrite.java, so I've added only the following dependency in my init.gradle:

    dependencies {
      rewrite("org.openrewrite:rewrite-java")
    }

When I am running the recipe, I'm getting the error

There were problems parsing 1 sources: build.gradle

As the recipe only refactors java files, I wonder, why build.gradle is parsed at all. How can I exclude build.gradle from being parsed?

2

There are 2 best solutions below

1
On

I found a solution. I've added the following to my init.gradle file:

 rewrite {
      exclusion(
        "**/*.gradle"
      )
0
On

I was using UpgradeDependencyVersion openrewrite-recipe on a big project and it used to give me heap memory overflow even after allocating 16 Gbs of heap memory.

The problem i found was that it was parsing unnecessary source files even if the recipe has nothing to do with that file.

Solution :

I created a helper directory with a pom.xml file with openrewrite-maven-plugin included, the files that would change (in my case pom.xml) i copied those files along with the directory structure in my helper folder and ran my recipe, this saved me from unnecessary parsing and even speed up the process, after the changes where made, i again synced the previous file with the changes in the helper folder.