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

ChangeDependencyClassifier should add explicit version when dependency-with-classifier is not managed #4646

Open
rcsilva83 opened this issue Nov 5, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@rcsilva83
Copy link
Contributor

What version of OpenRewrite are you using?

I am using

  • Maven plugin v5.43.1
  • rewrite-maven v8.38.0

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>

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

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.ChangeDependencyClassifier:
      groupId: com.querydsl
      artifactId: "*"
      newClassifier: jakarta
<?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>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.3.5</version>
    <relativePath/>
  </parent>

  <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?

No change or:

<?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>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.3.5</version>
    <relativePath/>
  </parent>

  <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>${querydsl.version}</version>
      <classifier>jakarta</classifier>
    </dependency>
  </dependencies>

</project>

What did you see instead?

<?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>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.3.5</version>
    <relativePath/>
  </parent>

  <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>
      <classifier>jakarta</classifier>
    </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

@rcsilva83 rcsilva83 added the bug Something isn't working label Nov 5, 2024
@timtebeek
Copy link
Contributor

Thanks for logging the issue! Am I correct in deducing that when you add a classifier, you want to version to be added when the dependency-with-classifier version is not managed?

@timtebeek timtebeek changed the title org.openrewrite.maven.ChangeDependencyClassifier: Adding classifier on dependency without version makes pom.xml invalid ChangeDependencyClassifier should add explicit version when dependency-with-classifier is not managed Nov 5, 2024
@rcsilva83
Copy link
Contributor Author

Sorry, @timtebeek . I didn't explain. It's confusing but Maven requires a <version> tag when you add a <classifier>. I've already filed an issue to them about it.

@timtebeek
Copy link
Contributor

I think we ought to be able to recognize when there's no matching managed dependency with the same classifier, and if so make the version explicit. Would welcome a draft PR that explores this with a unit test, and from there what would be necessary for a fix.

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

2 participants