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?

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.*

3 Comments

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?
Yes it's expected that the dependency is only added if you're using one of the classes that matches the onlyIfUsing argument.
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.