Hi all, When working with Gradle Tooling API, and ...
# community-support
s
Hi all, When working with Gradle Tooling API, and building a custom
ToolingModelBuilder
. Inside my
buildAll
method all instances I try to retrieve from
extensions
are
_Decorated
, and I cannot seem to find any by
findByType
nor can I unwrap or cast them to their actual types. Any ideas? I am using https://github.com/melix/gradle-tapi-demo-artifacts as an example.
v
That all classes are
_Decorated
is normal. Everything you let Gradle create for you is decorated, for example to implement all the boilerplate you can leave out like injected services and so on, or making all classes
ExtensionAware
whether they explicitly declare it or not. But those classes are subclasses of the actual classes, so you would still be able to find by type of cast, unless you for example try to cast to a class instance coming from a different class loader as usual.
So check and compare the class loaders involved in what you try to do
s
unless you for example try to case to a class instance coming from a different class loader as usual.
Aha, yes I think this is the case.
👌 1
> InstrumentingVisitableURLClassLoader(ClassLoaderScopeIdentifier.Id{coreAndPluginsinit file/var/folders/qs/9sb020z91_z1_f50v18bnmf00000gn/T/init1077651972231740836.gradle(export)}) > InstrumentingVisitableURLClassLoader(ClassLoaderScopeIdentifier.Id{coreAndPluginssettings[]buildSrc[]root project[](export)})
So there is a different classpath between initscript and the classpath when a
model
is requested from the
GradleConnector
using the Gradle Tooling API? So, I cannot access extensions from the connected project? 🤔
v
The init script classpath is not a parent of the other classpaths. So within the init script, you probably can not. You probably need instead to only use the init script to inject some code or plugin that is run in the scope of the build script classpath to do what you want or something like that. Didn't play too much with model building through tooling api yet.
s
I saw you in some similar related issues. This is currently my init script, and the problems lies within
kotlin-gradle-plugin
, where I replace
%%PLUGIN_JAR%%
with the actual path. Without the
kotlin-gradle-plugin
classpath the
JAR
will not work. What I understand from the Gradle Tooling APi is that it loads the projects, and then builds the models by running a task. So I guess I just have to add my plugin, with the classpath dependency to the rootProject. Seeing your issues, it seems there are some quirks surrounding that.
v
As I said, adding to the init script classpath does not add it to the project script classloaders. That's also why you cannot apply by ID from the init script but have to apply by class.
It might work if you add to the projects classpaths instead in your init script, not fully sure, didn't do much of those init script things myself so far