Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with resolving rewrite plugin on parent pom #475

Open
christianhahnsft22 opened this issue Jan 18, 2023 · 5 comments
Open

Problem with resolving rewrite plugin on parent pom #475

christianhahnsft22 opened this issue Jan 18, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@christianhahnsft22
Copy link

Hi !

When I try to use openrewrite inside a parent pom the rewrite maven plugin is not found. Here a sample parent pom:

<?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>com.old</groupId>
    <artifactId>old-artifactId</artifactId>
    <version>1.2.3</version>
    <packaging>pom</packaging>
    <name>my-name</name>
    <modules>
        <module>a</module>
        <module>b</module>
        <module>c</module>
        <module>project-ear</module>
    </modules>

    

    <dependencyManagement>
        <dependencies>
		....
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.openrewrite.maven</groupId>
                <artifactId>rewrite-maven-plugin</artifactId>
                <version>4.38.2</version>
                <configuration>
                    <activeRecipes>
                        <recipe>com.test.ChangePackage</recipe>
                    </activeRecipes>
                </configuration>
                <executions>
                    <execution>
                        <id>rewrite-source</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>runNoFork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
        <extensions>
            <extension>
                <groupId>org.apache.maven.wagon</groupId>
                <artifactId>wagon-ssh</artifactId>
                <version>3.4.3</version>
            </extension>
        </extensions>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.10.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.2.2</version>
                </plugin>
                ....
            </plugins>
        </pluginManagement>
    </build>
</project>

If I then try to call my recipe I cannot run mvn rewrite:run but need to call the plugin like this:

mvn org.openrewrite.maven:rewrite-maven-plugin:run

@timtebeek
Copy link
Contributor

Confirmed with Maven 3.8.7

$ mvn -version
Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29)
Maven home: /home/tim/.sdkman/candidates/maven/current
Java version: 17.0.5, vendor: Eclipse Adoptium, runtime: /home/tim/.sdkman/candidates/java/17.0.5-tem
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.15.0-58-generic", arch: "amd64", family: "unix"
$ mvn rewrite:run
[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml (14 kB at 61 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml (21 kB at 88 kB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.420 s
[INFO] Finished at: 2023-01-18T13:11:35+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'rewrite' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/home/tim/.m2/repository), central (https://repo.maven.apache.org/maven2)] -> [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/NoPluginFoundForPrefixException

@timtebeek timtebeek added the bug Something isn't working label Jan 18, 2023
@timtebeek
Copy link
Contributor

Reading the plugin prefix resolution documentation it's not clear to me why this would not resolve for this sample project. On one of my own multi module Maven projects the shorthand still works fine. Worst case you can configure a pluginGroup in your settings.xml, but that should not be necessary.

@christianhahnsft22
Copy link
Author

even if I add a goalPrefix it doesn't work

@timtebeek
Copy link
Contributor

So it appears we've encountered this before #103 ; the accidental way I found around this is using a profile on the parent.

<profile>
  <id>openrewrite</id>
  <build>
    <plugins>
      <plugin>
        <groupId>org.openrewrite.maven</groupId>
        <artifactId>rewrite-maven-plugin</artifactId>
        <version>4.38.2</version>
        <configuration>
          <activeRecipes>
            <recipe>org.openrewrite.java.cleanup.Cleanup</recipe>
          </activeRecipes>
          <failOnDryRunResults>true</failOnDryRunResults>
        </configuration>
      </plugin>
    </plugins>
  </build>
</profile>

Welcome to see if that will get you past this point for now and applying recipes!

@sansmoraxz
Copy link

Invoking dryRun through CLI works. All you need to do is build the project before invoking dryRun otherwise maven's dependency resolution fail.

For example, using shell command:

mvn -U org.openrewrite.maven:rewrite-maven-plugin:dryRun \
-Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:RELEASE \
-Drewrite.activeRecipes=org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_2

After than you can use git or patch cli to apply the generated patch file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

3 participants