openrewrite / rewrite-maven-plugin

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

Recipes in project dependencies not detected / usable #229

Open murdos opened 3 years ago

murdos commented 3 years ago

According to documentation, https://docs.openrewrite.org/tutorials/authoring-declarative-yaml-recipes#updating-downstream-projects, the maven plugin should detect recipes in directory /src/main/resources/META-INF/rewrite of project dependencies (as opposed to dependencies added to rewrite plugin in configuration).

However it doesn't currently work. This can easily be reproduced with the following simple pom.xml :

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.example</groupId>
  <artifactId>check-dependency-bug</artifactId>
  <version>1.0-SNAPSHOT</version>

  <dependencies>
    <dependency>
      <groupId>org.openrewrite.recipe</groupId>
      <artifactId>rewrite-migrate-java</artifactId>
      <version>0.10.0</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.openrewrite.maven</groupId>
        <artifactId>rewrite-maven-plugin</artifactId>
        <version>4.13.0</version>
        <configuration>
          <activeRecipes>
            <recipe>org.openrewrite.java.migrate.Java8toJava11</recipe>
          </activeRecipes>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

results in :

[INFO] --- rewrite-maven-plugin:4.13.0:run (default-cli) @ check-dependency-bug ---
[INFO] Using active recipe(s) [org.openrewrite.java.migrate.Java8toJava11]
[INFO] Using active styles(s) []
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by nonapi.io.github.classgraph.utils.ReflectionUtils$StandardReflectionDriver$1 (file:/home/amino/.m2/repository/io/github/classgraph/classgraph/4.8.123/classgraph-4.8.123.jar) to method sun.management.RuntimeImpl.getInputArguments()
WARNING: Please consider reporting this to the maintainers of nonapi.io.github.classgraph.utils.ReflectionUtils$StandardReflectionDriver$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.848 s
[INFO] Finished at: 2021-10-18T21:33:45+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:4.13.0:run (default-cli) on project check-dependency-bug: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:4.13.0:run failed: Recipes not found: org.openrewrite.java.migrate.Java8toJava11 -> [Help 1]
[ERROR]

NB : referencing a java recipe doesn't work either, e.g. with org.openrewrite.java.migrate.guava.NoGuavaAtomicsNewReference

jkschneider commented 3 years ago

Thanks @murdos . For context, in an earlier iteration all recipes were added to one of the regular dependency scopes. And we tried to keep dependencies really thin in rewrite jars to limit the potential for conflict resolution having an impact. But ultimately, the increased dependency isolation into the rewrite plugin configuration wound up being functionally necessary.

That shouldn't preclude us from also scanning Rewrite recipes where they happen to exist in regular dependency scopes. So I suggest we just do both going forward. Scanning from regular dependency scopes also permits framework authors to pack recipes into their own releases.