0

I am running a recipe on Mac OS from the command line using rewrite plugin version 4.46.0 The project is a multi module maven.

mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -e -Drewrite.activeRecipes=com.xxx.upgrade_18

My rewrite.yml is this

type: specs.openrewrite.org/v1beta/recipe
name: com.xxx.upgrade_18
displayName: XXXX
recipeList:
  - org.openrewrite.maven.AddDependency:
      groupId: com.xxx.yyy
      artifactId: zzzz
      version: 9.9.0

When I run I get a NPE:

    at org.openrewrite.internal.StringUtils.aspectjNameToPattern (StringUtils.java:647)
    at org.openrewrite.java.search.UsesType.<init> (UsesType.java:33)
    at org.openrewrite.maven.AddDependency.getApplicableTest (AddDependency.java:156)
    at org.openrewrite.Recipe.getApplicableTests (Recipe.java:395)

From what I have read the getApplicableTest is called on every file in the project. How can I find the root cause?

Christopher Helck
  • 1,130
  • 2
  • 8
  • 23

2 Answers2

0

If your recipe does not provide a value for ``onlyIfUsingthen NPE is thrown. What should the value ofonlyIfUsing``` be? I am still trying to figure it out.

Christopher Helck
  • 1,130
  • 2
  • 8
  • 23
0

onlyIfUsing limits the recipe to only add the recipe when certain import is used. That way you do not get unused dependencies added to just any project, especially with multi module projects.

The documentation for the recipe is here: https://docs.openrewrite.org/recipes/maven/adddependency

That gives a sample value of:

  onlyIfUsing: org.junit.jupiter.api.*

In your case you likely want to use a package from your dependency; possible something like com.xxx.yyy.*

Tim
  • 19,793
  • 8
  • 70
  • 95
  • I got it to work but I am still confused by what "using" means. If I use one of the package names or imports from a java file in my source tree then the dependency is added. Is this the expected behavior? I also noticed that when it adds a dependency it corrects the pom's indentation. Is that expected? – Christopher Helck May 20 '23 at 18:20
  • Yes it's expected that the dependency is only added if you're using one of the classes that matches the `onlyIfUsing` argument. – Tim May 21 '23 at 09:07
  • As for pom indentation; what kind of changes are you seeing, and are they problematic? We detect the predominant indentation style, and insert similar indentation. Feel free to raise an issue if you're seeing more than the expected changes – Tim May 21 '23 at 09:10