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

org.openrewrite.maven.UpgradeParentVersion adds <project.artifactId>null</project.artifactId> as Maven property #4122

Open
tjayling opened this issue Apr 4, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@tjayling
Copy link

tjayling commented Apr 4, 2024

Description of issue

When running the org.openrewrite.maven.UpgradeParentVersion recipe, any properties that are used in the pom, for example, project.artifactId but are not explicitly defined with that name, are added to the properties tag in the pom and are assigned a null value.
in our project, the following structure is used to define the project.artifactId:

<project ...>
    <artifactId>...</artifactId>
    ...
</project>

so while project.artifactId has not been defined with that exact key, it has been defined through the xml structure, meaning it does not need to be redefined in properties

This issues seems to have been introduced with this commit, and I think all that needs to be done is to also check that properties in use have not been defined via the structure of the pom, in addition to the current check for the existence of the property on line 105

What version of OpenRewrite are you using?

I am using

  • OpenRewrite v2.8.1
  • Maven/Gradle plugin v5.26.0
  • rewrite-spring v5.7.0

How are you running OpenRewrite?

I am using Maven plugin through command-line to run a custom recipe list, and my project is a single module project.
Project is private so can't share snippets

mvn -U org.openrewrite.maven:rewrite-maven-plugin:run \
-Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:RELEASE,ourGroupId:ourArtifactId:LATEST, \
-Drewrite.activeRecipes=ourGroupId.recipeName

What is the smallest, simplest way to reproduce the problem?

Create a pom file using a parent pom, with project, artifactId, and sonar.projectKey as follows:

<project ...>
    <artifactId>...</artifactId>
    ...
    <parent>
        ...
    </parent>
    <properties>
     <sonar.projectKey>${project.artifactId}</sonar.projectKey>
    ...
</project>

I don't think this is specific to sonar.projectKey, just anything using the property project.artifactId, or any other properties that aren't defined using dots, but rather are defined by the structure of the xml
Run a recipe that includes the below recipe on a project with a pom.xml that resembles the above.

  - org.openrewrite.maven.UpgradeParentVersion:
      groupId: xxx
      artifactId: xxx
      newVersion: xxx

What did you expect to see?

The parent pom upgraded to the specified version, and no other changes

What did you see instead?

The parent pom upgraded to the specified version, and a new property in the pom; <project.artifactId>null<project.artifactId>

<project ...>
    <artifactId>...</artifactId>
    ...
    <parent>
        ...
    </parent>
    <properties>
        <project.artifactId>null</project.artifactId>
        <sonar.projectKey>${project.artifactId}</sonar.projectKey>
    ...
</project>

Are you interested in contributing a fix to OpenRewrite?

Would like to but may not have the knowledge off the bat

@tjayling tjayling added the bug Something isn't working label Apr 4, 2024
@tjayling
Copy link
Author

tjayling commented Apr 4, 2024

org.openrewrite.maven.AddProperties.java

line 114:        } else if (!properties.get().getChildValue(key).isPresent()) {

doesn't check properties defined by xml structure

@PeteFreeGithub
Copy link

I'm encountering the same issue when running org.openrewrite.maven.ChangeParentPom:

@timtebeek
Copy link
Contributor

Sorry to hear about these issues! Indeed seems like something's off in how we determine which properties to add, possibly after

Would need a closer look. Thanks for bringing this to our attention.

@timtebeek timtebeek changed the title Null properties being added to maven projects when using org.openrewrite.maven.UpgradeParentVersion org.openrewrite.maven.UpgradeParentVersion adds <project.artifactId>null</project.artifactId> as Maven property May 9, 2024
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