openrewrite / rewrite-maven-plugin

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

AddPlugin Reports: Illegal character in path at index 72 #399

Closed rdifrango closed 1 year ago

rdifrango commented 2 years ago

I'm trying to use org.openrewrite.maven.AddPlugin and I'm getting the following failure:

Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:4.27.0:run failed: Illegal character in path at index 72: file:///Users/a683481/.m2/repository/org/apache/maven/maven-plugin-api/${project.prerequisites.maven}/maven-plugin-api-${project.prerequisites.maven}.pom

Here's the rewrite.yml:

---
type: specs.openrewrite.org/v1beta/recipe
name: com.difrango.AddSortPom
displayName: Add in the sortpom (https://github.com/Ekryd/sortpom) plugin.
recipeList:
  - org.openrewrite.maven.AddPlugin:
      groupId: com.github.ekryd.sortpom
      artifactId: sortpom-maven-plugin
      version: latest.release
      configuration: <configuration> <predefinedSortOrder>custom_1</predefinedSortOrder> <lineSeparator>\n</lineSeparator> <encoding>${project.build.sourceEncoding}</encoding> <nrOfIndentSpace>4</nrOfIndentSpace> <sortProperties>true</sortProperties> <sortDependencies>scope,groupId,artifactId</sortDependencies> </configuration>
      executions: <executions> <execution> <goals> <goal>sort</goal> </goals> <phase>verify</phase> </execution> </executions>
rdifrango commented 2 years ago

I'm still running into this with 4.31.3 thus I have to add -DskipMavenParsing=true to have any of the Java or Logging recipes run.

tkvangorder commented 2 years ago

@rdifrango Do you have a pom.xml or a sample project that can reproduce this problem?

Short of that, a stack trace would also be of great help.

Thanks!

rdifrango commented 2 years ago

Unfortunately, its a large multi-module project I'm working with, but the one thing that it has that none of the other project teams I'm working has is that it's using flatten-maven-plugin so perhaps that's causing issues, here's the plug-in configuration

<flatten-maven-plugin.version>1.1.0</flatten-maven-plugin.version>

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>flatten-maven-plugin</artifactId>
                <version>${flatten-maven-plugin.version}</version>
                <configuration>
                    <updatePomFile>true</updatePomFile>
                    <flattenMode>bom</flattenMode>
                </configuration>
                <executions>
                    <execution>
                        <id>flatten</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>flatten</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>flatten.clean</id>
                        <phase>clean</phase>
                        <goals>
                            <goal>clean</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
rdifrango commented 2 years ago

and as an FYI...for this project I have to continuously disable Maven POM parsing to get it to work. Now I do know plugin and plugin management in it is a bit all over the place so I'm working to fix that but I'd also argue it should be supported.

tkvangorder commented 2 years ago

@rdifrango Can you try this now with the latest 4.32.0 version?

I believe this was fixed as part of this work:

https://github.com/openrewrite/rewrite/commit/92a5be3ffe06cd66099c336b232416fd93a78e49

rdifrango commented 2 years ago

unfortunately the problem seems to persist:

[ERROR] Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:4.32.0:run (default-cli) on project dp-vault-ecc: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:4.32.0:run failed: Illegal character in path at index 72: file:///Users/a683481/.m2/repository/org/apache/maven/maven-plugin-api/${project.prerequisites.maven}/maven-plugin-api-${project.prerequisites.maven}.pom -> [Help 1]

and my rewrite config:

<rewrite-logging-frameworks.version>1.10.1</rewrite-logging-frameworks.version>
<rewrite-maven-plugin.version>4.32.0</rewrite-maven-plugin.version>
<rewrite-migrate-java.version>1.9.1</rewrite-migrate-java.version>

<plugin>
        <groupId>org.openrewrite.maven</groupId>
        <artifactId>rewrite-maven-plugin</artifactId>
        <version>${rewrite-maven-plugin.version}</version>
        <configuration>
            <activeRecipes>
                <!-- Converts from log4j to slf4j -->
                <recipe>org.openrewrite.java.logging.slf4j.Log4jToSlf4j</recipe>
                <recipe>org.openrewrite.java.logging.slf4j.Log4j1ToSlf4j1</recipe>
                <recipe>org.openrewrite.java.logging.slf4j.Log4j2ToSlf4j1</recipe>
                <!-- These recipes ensure proper log formatting. -->
                <recipe>org.openrewrite.java.logging.slf4j.ParameterizedLogging</recipe>
                <recipe>org.openrewrite.java.logging.slf4j.Slf4jLogShouldBeConstant</recipe>
                <recipe>org.openrewrite.java.logging.slf4j.ConvertLogMessageMessageOnlyToLogMessageAndThrowable</recipe>
                <recipe>org.openrewrite.java.logging.PrintStackTraceToLogError</recipe>
            </activeRecipes>
        </configuration>
        <dependencies>
            <dependency>
                <groupId>org.openrewrite.recipe</groupId>
                <artifactId>rewrite-logging-frameworks</artifactId>
                <version>${rewrite-logging-frameworks.version}</version>
            </dependency>
            <dependency>
                <groupId>org.openrewrite.recipe</groupId>
                <artifactId>rewrite-migrate-java</artifactId>
                <version>${rewrite-migrate-java.version}</version>
            </dependency>
        </dependencies>
    </plugin>
tkvangorder commented 1 year ago

@rdifrango I was just looking through our backlog and came across this issue. Does your maven pom.xml file include the <prerequisites> tag?

I think this just may be a case where we should be generating an implicit property based on if this tag exists. (Currently, rewrite' maven model is does not include prerequisites)

timtebeek commented 1 year ago

Closing due to inactivity. Feel free to reopen if the problem persists with the latest versions.