hi, how I can do it right?
# gradle
l
hi, how I can do it right?
g
arrayOf
->
listOf
?
Oh, I see, you cannot use
+=
here
just add element using add
options.compilerArgs.add("someArg")
or something like
addAll
l
yes, thnx
tasks.withType<JavaCompile> { options.compilerArgs.addAll(arrayOf("S", generatedPath)) }
g
I don’t think that Collection has method addAll for array, probably you need
listOf
instead
oh no
sorry, yes, it has
anyway, I would recommend to use
listOf
always
l
of course it has
why plus assign is not win there?
another question, why
plus
also chosen? 🙂
maybe because
plusAssign
is inline?
g
Because Kotlin cannot choose between MutableList and Collection operator overloading, because doesn’t know type of this list with platform type. In case of Kotlin List will be created a new list with new content and assigned to variable/field, in case of MutableList new element will be added to an existing list
l
yes, a look at realization. ok, it is just receiver determination problem
g
and it’s hard to decide what to do without knowing type: 1. Kotlin create a new list from
options.compilerArgs
(call
getCompilerArgs
) + your arguments and call
setCompilerArgs
with a new list as argument 2. Or just call
getCompilerArgs
and add elements to existing list
l
yes
g
it’s problem of Gradle API. Maybe make sense to rise an issue, maybe Gradle Team would solve it at least for bundled Gradle plugins
👍 1
also approach with
add
,
addAll
works not for all the apis of Gradle and especially third-party plugins. Many API return defence copy of list from getter, so you always should check implementation, or use setter, but in this case you can override some default values
👍 1