-
Notifications
You must be signed in to change notification settings - Fork 200
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
can't modify unresolved.dependencies #704
Comments
I also tried to copy unresolved.dependencies to a new SortedSet (lets name it mySet), remove unwanted items from this set, then do |
Thanks @jonathanlermitage. I'm not very familiar with Kotlin yet, but you are welcome to send a PR with your improvement ideas. |
Sure, no problem, I will look at this. |
@ben-manes I was able to update unresolved.dependencies by changing its type from Set to TreeSet, but I'm not happy with this workaround. We should keep unmodifiable collections, this is a good thing.
I will see if I can add some unit test, then I will create a pull request very soon. |
I think you might use a MutableSet instead? I agree immutability is a nice practice, but mutability is simple for any manipulations like your original example. If one has other use cases then the pattern has to be extended to more categories. So I slightly prefer mutability for scripting as it helps get the job done and is not in a usage that can cause trouble. Otherwise if there is just as easy way via builders then you can get equivalent behaviors. wdyt? |
I see, good idea! I will create a PR asap with a MutableSet 😀 |
Starting from version 0.43.0 I can no longer modify the value of the
unresolved.dependencies
property.Example: https://github.com/jonathanlermitage/intellij-extra-icons-plugin/blob/master/build.gradle.kts#L178-L187
(I'm doing this because Gradle can't find some artifacts version, like com.jetbrains:ideaIU. This is not a blocker issue, this is purely cosmetic. I'm curious... ^_^)
Actually, Gradle's error is weird: I ran
gradlew dependencyUpdates
and I got this error:Line 179 refers to
unresolved.dependencies.removeIf
.It makes no sens. This is a SortedSet (I checked this with a debugger), so I should be able to invoke
removeIf
. I also tried to invokeclear()
and I faced the same issue. But it seems to be a Set, because I can iterate over this set withforeach
.Maybe this is a side effect of the recent Kotlin migration? Some Kotlin basic collections are immutable. The debugger says this is a SortedSet from java.util, but I already observed some bugs with JDK17 and Kotlin: some lists from java.util were silently replaced by their equivalent class from Kotlin standard lib; at least for methods which declares a List return type but actually returns a java.util.ArrayList. It made me crazy. I finally fixed this by replacing the java.util.list return type by java.util.ArrayList, and replacing star imports of java.util by single-class imports, otherwise Kotlin seemed to pick the ArrayList from the Kotlin standard lib instead of java.util.*. It was super weird because it did not fail at compile-time, but at runtime, with Java17 only (no problem with Java11): ArrayList from Kotlin std lib couldn't be casted to java.util.ArrayList ^_^.
The text was updated successfully, but these errors were encountered: