ok, related issue: how do I define a generatedBy i...
# gradle
b
ok, related issue: how do I define a generatedBy in a multiplatform sourceset? I've got a task that generates json files into build/generated/resources which need to be picked up by commonMain. I supopse it's something along the lines of
Copy code
resources.srcDir(tasks.named<CombineJsonFiles>("combineJsonFiles"))
but I'm getting a Task with name 'combineJsonFiles' not found in root project 'pfrpg2eKingdomCampingWeather'.
1
j
That is correct, are you sure the task is already registered? If you do
Copy code
resources.srcDir(tasks.withType<CombineJsonFiles>())
Does it work? If this last is working, probably you are calling
register
after
named
and that is the reason it is not found.
b
the task is registered further down in the source file, is order important? I thought it was evaluated lazily
j
AFAIK register/named has that issue. You need to call register before named
I think
named { }
would work, it was added recently
Copy code
resources.srcDir(tasks.named { it == "combineJsonFiles" })
b
how recently? I'm on 8.10
j
There should be included
b
does not compile
ah, type argument has to be removed
👍 1
thank you
v
The type argument would go in a preliminary
withType<...>()
before doing
named { ... }
. But be careful.
.named { ... }
does not work like advertised yet. If not combined with
configureEach { ... }
it will break task-configuration avoidance, in your case for each and every task, if combined with
withType
just for all tasks of that type. Better register the task first and then give the returned task provider to
srcDir
, then you are on the safe side.
b
thank you!
👌 1