Skip to content

Error while visiting src/main/java/com/todo/app/AppApplication.java: java.lang.IllegalStateException: Unable to construct Java21Parser #64

@cmoulliard

Description

@cmoulliard

Issue

One of the recipe fails and reports the following error

Caused by: java.lang.RuntimeException: Error while visiting src/main/java/com/todo/app/AppApplication.java: java.lang.IllegalStateException: Unable to construct Java21Parser.
  org.openrewrite.java.Java21Parser$Builder.build(Java21Parser.java:96)
  org.openrewrite.java.Java21Parser$Builder.build(Java21Parser.java:63)
  org.openrewrite.java.internal.template.JavaTemplateParser.compileTemplate(JavaTemplateParser.java:273)
  org.openrewrite.java.internal.template.JavaTemplateParser.lambda$parseAnnotations$10(JavaTemplateParser.java:234)
  org.openrewrite.java.internal.template.JavaTemplateParser.cache(JavaTemplateParser.java:337)
  org.openrewrite.java.internal.template.JavaTemplateParser.parseAnnotations(JavaTemplateParser.java:231)
  org.openrewrite.java.internal.template.JavaTemplateJavaExtension$1.visitAnnotation(JavaTemplateJavaExtension.java:63)
  org.openrewrite.java.internal.template.JavaTemplateJavaExtension$1.visitAnnotation(JavaTemplateJavaExtension.java:56)
  org.openrewrite.java.tree.J$Annotation.acceptJava(J.java:229)
  org.openrewrite.java.tree.J.accept(J.java:55)
  org.openrewrite.TreeVisitor.visit(TreeVisitor.java:242)
  org.openrewrite.TreeVisitor.visit(TreeVisitor.java:154)
  org.openrewrite.java.JavaTemplate.apply(JavaTemplate.java:121)
  dev.snowdrop.openrewrite.recipe.spring.ReplaceSpringBootApplicationWithQuarkusMainAnnotation$SpringBootToQuarkusMainVisitor.visitAnnotation(ReplaceSpringBootApplicationWithQuarkusMainAnnotation.java:55)

The error comes from the fact that the rewrite Java parser cannot find from the classpath "quarkus-core"

Fix

To fix this issue it is needed to generate using the following goal the typetables packaging the needed classes, jars as documented here: https://docs.openrewrite.org/authoring-recipes/multiple-versions#typetable-generation-for-maven-projects

mvn org.openrewrite.maven:rewrite-maven-plugin:typetable -Drewrite.recipeArtifactCoordinates="io.quarkus:quarkus-core:3.29.0"

TODO

Add to the pom.xml of the openrewrite-recipes module the following plugin and dependencies needed

<profiles>
    <!--
        When you want to generate a TypeTable for use in JavaParser for JavaTemplate, run the following command:
        ./mvnw generate-resources -Ptypetable
    -->
    <profile>
        <id>typetable</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.openrewrite.maven</groupId>
                    <artifactId>rewrite-maven-plugin</artifactId>
                    <version>6.9.0-SNAPSHOT</version>
                    <configuration>
                        <recipeArtifactCoordinates>
                            junit:junit:3.8.1,
                            junit:junit:4.13.2,
                            org.mockito:mockito-core:2.16.0,
                            org.mockito:mockito-core:3.12.4
                        </recipeArtifactCoordinates>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>typetable</goal>
                            </goals>
                            <phase>generate-resources</phase>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions