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

Compile asset-pipeline-core with Groovy 3 #350

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

jamesfredley
Copy link

@jamesfredley jamesfredley commented Sep 13, 2024

Compile asset-pipeline-core with Groovy 3 to avoid Groovy 4 incompatibility when Gradle runs it in asset-pipeline-gradle with Groovy 3

When compiled with Groovy 4, the compiler uses groovy.lang.IntRange(boolean, boolean, int, int), which does not exist in Groovy 3 and causes the NoSuchMethodError when Gradle runs the class with Groovy 3.0.22.

The specific line that gets transformed to use groovy.lang.IntRange(boolean, boolean, int, int) when compiled with Groovy 4, which does not exist in Groovy 3. https://docs.groovy-lang.org/3.0.22/html/api/groovy/lang/IntRange.html

return (pathArgs[0..(pathArgs.size()-2)]).join("/")

Compiled with Groovy 3:

return pathArgs.size() == 1 ? (String)ShortTypeHandling.castToString((Object)null) : DefaultGroovyMethods.join(DefaultGroovyMethods.getAt(pathArgs, new IntRange(true, 0, pathArgs.size() - 2)), "/");

Compiled with Groovy 4:

return pathArgs.size() == 1 ? null.cast((Object)null) : DefaultGroovyMethods.join(DefaultGroovyMethods.getAt(pathArgs, new IntRange(true, true, 0, pathArgs.size() - 2)), "/");

…bility when Gradle runs it in asset-pipeline-gradle with Groovy 3
@codeconsole
Copy link
Contributor

@jamesfredley what is it about Groovy 4 that is causing the NoSuchMethodError?

@jamesfredley
Copy link
Author

jamesfredley commented Sep 13, 2024

@codeconsole The dependency (asset-pipeline-core) was compiled with Groovy 4. Groovy 4 has a new method groovy.lang.IntRange(boolean, boolean, int, int) which the compiler used in the generated class, which then failed when Gradle tried to runs it on Groovy 3.0.22 during the build because that method did not exist in Groovy 3.

The Gradle build is still executing using the included Groovy libraries, unfortunately.

@jamesfredley
Copy link
Author

I think this is the root underlying issue Gradle is trying to warn user about with:

"Gradle plugins written in Groovy must use Groovy 3.x for compatibility with Gradle and Groovy DSL build scripts.
https://docs.gradle.org/current/userguide/compatibility.html#groovy

@codeconsole
Copy link
Contributor

@jamesfredley can we just tweak the method a bit so it runs on both?

@jamesfredley
Copy link
Author

@codeconsole It would have to be refactored to not use a range, since that is what is triggering this.

@codeconsole
Copy link
Contributor

@jamesfredley that should be re-written. It seems overly complicated as is.

Isn't

return (pathArgs[0..(pathArgs.size()-2)]).join("/") 

the same as

pathArgs[0..-2).join("/")

no need for return either

@codeconsole
Copy link
Contributor

List<String> pathArgs = 'abc/def/ghi/jkl/mno'.tokenize('/')
assert pathArgs[0..pathArgs.size()-2] == pathArgs[0..-2]

@davydotcom davydotcom merged commit 5d87f8c into bertramdev:5.0.x Sep 13, 2024
@davydotcom
Copy link
Contributor

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants