openrewrite / rewrite

Automated mass refactoring of source code.
https://docs.openrewrite.org
Apache License 2.0
2.21k stars 329 forks source link

org.openrewrite.maven.UpgradeDependencyVersion doesn't add a version if there wasn't one previously #4638

Open rcsilva83 opened 5 days ago

rcsilva83 commented 5 days ago

What version of OpenRewrite are you using?

I am using

How are you running OpenRewrite?

I am using the Maven plugin, and my project is a multi-module project.

      <plugin>
        <groupId>org.openrewrite.maven</groupId>
        <artifactId>rewrite-maven-plugin</artifactId>
        <version>5.43.1</version>
        <configuration>
          <activeRecipes>
            <recipe>my.company.rewrite.recipe.MyRecipe</recipe>
          </activeRecipes>
          <exportDatatables>true</exportDatatables>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>my.company.rewrite.recipe</groupId>
            <artifactId>my-rewrite</artifactId>
            <version>1.0.0-SNAPSHOT</version>
          </dependency>
        </dependencies>
      </plugin>

And this is MyRecipe:

type: specs.openrewrite.org/v1beta/recipe
name: my.company.rewrite.recipe.MyRecipe
displayName: My Recipe
description: This is an OpenRewrite recipe
recipeList:
  - org.openrewrite.maven.UpgradeDependencyVersion:
      groupId: com.querydsl
      artifactId: "*"
      newVersion: 5.1.0

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

<?xml version="1.0" encoding="UTF-8"?>
<project
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://maven.apache.org/POM/4.0.0"
  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>my.company.myapp</groupId>
  <artifactId>myapp</artifactId>
  <packaging>jar</packaging>
  <name>My App</name>

  <dependencies>
    <dependency>
      <groupId>com.querydsl</groupId>
      <artifactId>querydsl-jpa</artifactId>
    </dependency>
  </dependencies>

</project>

What did you expect to see?

<?xml version="1.0" encoding="UTF-8"?>
<project
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://maven.apache.org/POM/4.0.0"
  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>my.company.myapp</groupId>
  <artifactId>myapp</artifactId>
  <packaging>jar</packaging>
  <name>My App</name>

  <dependencies>
    <dependency>
      <groupId>com.querydsl</groupId>
      <artifactId>querydsl-jpa</artifactId>
      <version>5.1.0</version>
    </dependency>
  </dependencies>

</project>

What did you see instead?

Nothing changed:

<?xml version="1.0" encoding="UTF-8"?>
<project
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://maven.apache.org/POM/4.0.0"
  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>my.company.myapp</groupId>
  <artifactId>myapp</artifactId>
  <packaging>jar</packaging>
  <name>My App</name>

  <dependencies>
    <dependency>
      <groupId>com.querydsl</groupId>
      <artifactId>querydsl-jpa</artifactId>
    </dependency>
  </dependencies>

</project>

What is the full stack trace of any errors you encountered?

None

Are you interested in contributing a fix to OpenRewrite?

Yes. If you agree with this bug report, I can implement as I already implemented a recipe from scratch.

timtebeek commented 5 days ago

hi! Did you also try the property overrideManagedVersion already? That's set to false by default: https://docs.openrewrite.org/recipes/maven/upgradedependencyversion

mccartney commented 4 days ago

I suppose the sections:

What is the smallest, simplest way to reproduce the problem?
What did you expect to see?
What did you see instead?

are messed up in the description.

The observed is without the <version>5.1.0</version>. The expected is with the line. And the foo-bar is irrelevant.

rcsilva83 commented 2 days ago

@timtebeek , I tried but it didn't work either.

@mccartney , sorry about that. I fixed.