openrewrite / rewrite-maven-plugin

OpenRewrite's Maven plugin.
https://openrewrite.github.io/rewrite-maven-plugin/plugin-info.html
Apache License 2.0
146 stars 76 forks source link

rewrite-maven-plugin:4.17.0-SNAPSHOT:dryRun failed.: NullPointerException #269

Closed ruben-garciapariente closed 2 years ago

ruben-garciapariente commented 2 years ago

Hello:

This error happens with version 4.17.0-SNAPSHOT of rewrite-maven-plugin but does not occur with version 4.16.0.

I'm using the recipe

recipeList:
  - org.openrewrite.maven.AddDependency:
      groupId: com.google.guava
      artifactId: guava
      version: 29.X
      onlyIfUsing: org.junit.jupiter.api.*
      versionPattern: -jre

I have in my setting.xml the activeByDefault enabled

<profiles>
    <profile>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>

If I try to execute the plugin I have the next error

λ mvn rewrite:dryRun
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< com.test.project:test-openrewrite >------------------
[INFO] Building Test 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> rewrite-maven-plugin:4.17.0-SNAPSHOT:dryRun (default-cli) > process-test-classes @ test-openrewrite >>>
[INFO]
[INFO] --- maven-resources-plugin:2.7:resources (default-resources) @ test-openrewrite ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ test-openrewrite ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.7:testResources (default-testResources) @ test-openrewrite ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\n129586\workspace\test-openrewrite\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ test-openrewrite ---
[INFO] No sources to compile
[INFO]
[INFO] <<< rewrite-maven-plugin:4.17.0-SNAPSHOT:dryRun (default-cli) < process-test-classes @ test-openrewrite <<<
[INFO]
[INFO]
[INFO] --- rewrite-maven-plugin:4.17.0-SNAPSHOT:dryRun (default-cli) @ test-openrewrite ---
[INFO] Using active recipe(s) [com.yourorg.AddDependencyExample]
[INFO] Using active styles(s) []
[INFO] Validating active recipes...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  56.119 s
[INFO] Finished at: 2021-12-15T15:35:29+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:4.17.0-SNAPSHOT:dryRun (default-cli) on project test-openrewrite: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:4.17.0-SNAPSHOT:dryRun failed.: NullPointerException -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

but if I comment activation node in settings.xml all works ok

<profiles>
    <profile>
        <!--<activation>
            <activeByDefault>true</activeByDefault>
        </activation>-->

To repeat the problem, the following code can be executed https://github.com/ruben-garciapariente/test-openwrite/tree/maven-system-property but it is also necessary to add to the settings.xml the activeByDefault node

Many thanks and regards

aegershman commented 2 years ago

Thanks @ruben-garciapariente taking a look 👍

aegershman commented 2 years ago

(I forgot the keyword "fixes" would close this issue, apologies).

@ruben-garciapariente The fix is now available in latest snapshot; could you try this out again and @ me if it still has a null pointer? This should be good to go. Thanks for logging this.