Reading task dependencies in Isolated Projects mod...
# plugin-development
a
Reading task dependencies in Isolated Projects mode I can't seem to get
task.getTaskDependencies().getDependencies(task)
to work when Isolated Projects are enabled. Is there a way or an alternative to that in Isolated Projects mode? Interestingly, while
task.getTaskDependencies().getDependencies(task)
return task dependencies,
task.getDependsOn()
returns an empty set. Thanks!
The error I'm getting is
Copy code
org.gradle.api.InvalidUserCodeException: Project ':' cannot access task dependencies directly
m
Yea, that sounds like something PI would disallow. Can you share more of your use case? Maybe there's another solution?
a
I need to find out which Jar tasks are enabled in a project and which classifiers they will use for the jars they will create. This part works. Then I also need to know which directories they will use as the source of content.
To find out that, I’m going through jar task dependencies
Since those tasks haven’t been executed yet, those directories might not exist on the disk yet
The error says the project can’t access task dependencies directly, I was wondering whether there was another way
m
In that case, I would export the source directories as an outgoing variant with a specific attribute. Then resolve that from your other project
With PI, outgoing variant is almost always the answer.
a
That means I’d need to apply a plug-in that would do that in that other project, right?
1
Or rather a user of my plug-in
m
Yea, both projects need to cooperate
I don't think you can access the internals without breaking project isolation. It's kind of the point of project isolation
a
Yeah, that’s unfortunate though
Actually, there are two cases
One is where I’d need other project’s jar info
The other one is when I need the current project’s jar info
So far I wasn’t able to do that in the project where my plug-in is applied
Source sets wouldn’t be enough, afaiu
The only way to get the jar content source would be to read the jar task dependencies, it seems
m
Did you consider just extracting the Jar? You would get all the files and directories
Or do you really need the exact root directories that were used as input?
a
The jar hasn’t been built yet
m
Just build it?
a
Even the tasks the jar depends on haven’t been executed at that point
I can’t execute those tasks because it’s for the task that needs to be executed before those tasks
m
That sounds like a cyclic dependency?
a
From the task perspective yes
I don’t need the content of the jar though
I need the destination directories of the tasks the jar task depends on
m
Does your
processJarInputDir
need to be executed before
createSomeContent
?
Sounds like yes. But
processJarInputDir
does not need the actual content, just the
CreateSomeContent.outputDir
?
Maybe
processJarInputDir
could "just" be some configuration code?
a
Sounds like that, I just could not figure out how to capture that
v
I'm curious, what do you do with the information you are gathering?
a
I’m figure out which source directories are contributing to which jar
v
But why? What do you do with that information?
a
This is currently necessary to decide which class path element will end up in which class loader
There is also watching for changes involved
a
Can you use
((DefaultCopySpec) yourArchiveTask.getRootSpec()).getSourcePaths()
and recursively for
((DefaultCopySpec) yourArchiveTask.getRootSpec()).getChildren
. Unless I've misunderstood what you want.
🏅 1
a
@Arthur McGibbon, it seems like it's working! Thanks a lot!
it appears to be an internal API and there is some casting involved iterating through the
sourcePaths
but it appears to be working with Isolated Projects enabled
a
All Gradle best bits are internal
v
Just the ones you should never use from outside. 😛
😄 2
a
i really appreciate all your advises, guys
👌 1