openrewrite / rewrite-maven-plugin

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

Error: Maven visitors should not be visiting XML documents without a Maven marker #297

Closed josemariavillar closed 2 years ago

josemariavillar commented 2 years ago

Good morning,

I am having problems using the version (4.19.0 or 4.18.0) of the rewrite-maven-plugin. When I run the command "mvn rewrite:run" I get the following error.

[INFO] <<< rewrite-maven-plugin:4.19.0:run (default-cli) < process-test-classes @ migration_from_darwin_2.x <<<
[INFO]
[INFO]
[INFO] --- rewrite-maven-plugin:4.19.0:run (default-cli) @ migration_from_darwin_2.x ---
[INFO] Using active recipe(s) [com.yourorg.UpgradePom]
[INFO] Using active styles(s) []
[INFO] Validating active recipes...
[INFO] Parsing Java main files...
[INFO] Parsing Java test files...
[INFO] Running recipe(s)...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  01:25 min
[INFO] Finished at: 2022-02-16T11:27:41+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:4.19.0:run (default-cli) on project 
migration_from_darwin_2.x: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:4.19.0:run failed: 
java.lang.IllegalStateException: Maven visitors should not be visiting XML documents without a Maven marker -> [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

I have tried with the previous version, 4.17.4, and it works correctly.

The POM I useis:

<?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>es.santander.nuar</groupId>
    <artifactId>migration_from_darwin_2.x</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>Project Test</name>
    <description>Project Test</description>

    <!-- Use starter parent -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.9.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <dependencies>
        <!-- Spring Framework dependencies -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- Test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <maxAttempts>600</maxAttempts>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openrewrite.maven</groupId>
                <artifactId>rewrite-maven-plugin</artifactId>
                <version>4.19.0</version>
                <configuration>
                    <activeRecipes>
                        <recipe>com.yourorg.UpgradePom</recipe>
                    </activeRecipes>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

And the recipes to run:

type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.UpgradePom
displayName: Upgrade POM
recipeList:
  - org.openrewrite.maven.UpgradeParentVersion:
      groupId: org.springframework.boot
      artifactId: spring-boot-starter-parent
      newVersion: 2.3.X

  - org.openrewrite.maven.RemoveDependency:
      groupId: org.springframework.boot
      artifactId: spring-boot-starter-web

  - org.openrewrite.maven.AddDependency:
      groupId: org.springframework.boot
      artifactId: spring-boot-starter-webflux
      version: 2.3.X
      onlyIfUsing: org.springframework.boot.*

  - org.openrewrite.maven.AddDependency:
      groupId: org.springframework.boot
      artifactId: spring-cloud-starter-config
      version: 2.3.X
      onlyIfUsing: org.springframework.boot.*
traceyyoshima commented 2 years ago

Hi @josemariavillar, thanks for reporting the issue! I stumbled across this while looking into a different issue with the latest changes.

I've identified the cause and am working on a fix!