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

StringIndexOutOfBoundsException while using rewrite-gradle-plugin #4974

Open
man85 opened this issue Jan 30, 2025 · 6 comments
Open

StringIndexOutOfBoundsException while using rewrite-gradle-plugin #4974

man85 opened this issue Jan 30, 2025 · 6 comments
Labels
bug Something isn't working

Comments

@man85
Copy link

man85 commented Jan 30, 2025

I have a Kotlin project managed by Gradle.
build.gradle.kts:

plugins {
   kotlin("jvm") apply false
   id("org.openrewrite.rewrite") version "7.0.4"
}

rewrite {
   activeRecipe("com.yourorg.ChangePluginVersionExample")
}

rewrite.yml:

---
type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.ChangePluginVersionExample
displayName: Change a Gradle plugin version by id example
recipeList:
  - org.openrewrite.gradle.plugins.ChangePluginVersion:
      pluginIdPattern: net.razvan.jacoco-to-cobertura
      newVersion: 1.3.2
      versionPattern: '-jre'

When I run gradle rewriteRun --stacktrace I get an error:

Caused by: java.lang.StringIndexOutOfBoundsException: Range [1, 0) out of bounds for length 0
        at java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:55)
        at java.base/jdk.internal.util.Preconditions$1.apply(Preconditions.java:52)
        at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:213)
        at java.base/jdk.internal.util.Preconditions$4.apply(Preconditions.java:210)
        at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:98)
        at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckFromToIndex(Preconditions.java:112)
        at java.base/jdk.internal.util.Preconditions.checkFromToIndex(Preconditions.java:349)
        at org.openrewrite.java.marker.JavaSourceSet.gavFromPath(JavaSourceSet.java:243)
        at org.openrewrite.java.marker.JavaSourceSet.build(JavaSourceSet.java:206)
        at org.openrewrite.gradle.isolated.DefaultProjectParser.parseGradleProjectSourceSets(DefaultProjectParser.java:891)
        at org.openrewrite.gradle.isolated.DefaultProjectParser.parse(DefaultProjectParser.java:689)
        ... 125 more

I suppose the reason is here

@jkschneider @sambsnyd

@MBoegers
Copy link
Contributor

Hi @man85 👋 , could you share a little more of your build.gradle.kts? What I am looking for is the plugin definition of net.razvan.jacoco-to-cobertura to easily create a reproducing test.

@shanman190
Copy link
Contributor

The most likely suspect is that one of the subprojects of the Gradle project itself ends with "repository" and then JavaSourceSet gets tripped up since the dependency points to a local jar (repository/build/libs/repository-<version>.jar) of that project's build.

@greg-at-moderne
Copy link
Contributor

If so, that would make it related or similar to #4470.

@greg-at-moderne greg-at-moderne added the bug Something isn't working label Jan 31, 2025
@man85
Copy link
Author

man85 commented Jan 31, 2025

definition of net.razvan.jacoco-to-cobertura to easily create a reproducing test.

There is no definition of net.razvan.jacoco-to-cobertura in a current project. It is transitively added by other plugin to the project. Can Openrewrite handle this situation: changing the version of a transitive plugin?

@man85
Copy link
Author

man85 commented Jan 31, 2025

one of the subprojects of the Gradle project itself ends with "repository"

You are absolutely right ) One of the subprojects is named repository

@shanman190
Copy link
Contributor

Can Openrewrite handle this situation: changing the version of a transitive plugin?

The way that this works for Gradle -- which is not OpenRewrite specific -- is by either changing the dependency version found in buildscript or changing the version via declaring the plugin as a first-order plugin. Gradle additionally supports changing the version by resolution rules within the settings.gradle script.

As far as OpenRewrite goes, the easiest way to alter the version would be with the AddBuildPlugin recipe to add the specified plugin as a first order plugin dependency.

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: No status
Development

No branches or pull requests

4 participants