When using the Tooling API, how does one attach a ...
# plugin-development
s
When using the Tooling API, how does one attach a debugger to the embedded gradle process that’s started? I’d like to debug a
ModelBuilder
, and using sysout debugging isn’t really working well for me.
v
Which embedded process? You mean the external Gradle daemon process that is started and which you can give debug properties just the usual way and then attach as debugger? :-)
s
That’s the one. I’ve tried passing
-Dorg.gradle.debug=true
to
modelBuilder.withArguments
, but the daemon process definitely doesn’t stop and wait for a debugger.
Attempting to pass
--no-daemon
causes an exception stating that
--daemon
is an unsupported build option.
v
For a normal tooling api triggered build it works fine. Doing
Copy code
GradleConnector
    .newConnector()
    .forProjectDirectory(file("."))
    .connect()
    .use {
        it
            .newBuild()
            .withArguments("-Dorg.gradle.debug=true")
            .run()
    }
stops and waits for a debugger to get attached unless other options are used like
org.gradle.debug.server = false
in the user-level
gradle.properties
.
Also
Copy code
interface Foo
GradleConnector
    .newConnector()
    .forProjectDirectory(file("."))
    .connect()
    .use {
        it
            .model(Foo::class.java)
            .withArguments("-Dorg.gradle.debug=true")
            .get()
    }
works fine and as expected.
s
I’m currently using Gradle 7.6. Maybe I should try a newer release
v
As with
org.gradle.debug.server = false
it would fail if no debugger listens, I guess you have
org.gradle.debug.suspend = false
somewhere as that would then behave as you describe. It would listen for a debugger but not wait
I quickly tried with 7.6.4 also there works just fine
s
Copy code
ProjectConnection connection = connector.connect();
        OutgoingArtifactsModel model = connection.model(OutgoingArtifactsModel.class)
                .withArguments("-Dorg.gradle.debug=true", "--init-script", copyInitScript().getAbsolutePath())
                .get();
isn’t working for me with 7.6.4.
v
As I said, only thing I can imagine right now is that you set
org.gradle.debug.suspend = false
somewhere. Maybe try to explicitly supply it in that call as
-Dorg.gradle.debug.suspend=true
?
I can only say that it works just fine here. If that also doesn't help, maybe provide and MCVE.
s
Still not working, but I’m learning more about flags 🙂
Thank you for your help, it’s much appreciated
👌 1
I reckon I can get most of this working in a regular gradle instance, and once it’s working I’ll back away very slowly and hope that nothing breaks 🙂
v
Well, really strange, but hard to say from here without an MCVE
s
The code is all here. It builds and runs using
bazel
, so you’ll to have that available. I’d recommend installing bazelisk and renaming the binary
bazel
(you can think of
bazelisk
as the equivalent of
gradlew
, in that it allows a build to pin the version of bazel it’s using) I set the arguments to pass to the model here. Once you’ve got that, you can run everything using
bazel run private/tools/java/com/github/bazelbuild/rules_jvm_external/resolver/cmd:Resolver -- --resolver gradle 'com.google.guava:guava:33.2.1-jre'
If you set the env var
RJE_DEBUG=1
we should hit the debugger.
v
Oh, well, I'm not going to install Bazel just to test this, sorry. That project does not qualify for the "M" in "MCVE". 🙂
s
Hahaha! Understandable 🙂
Thanks anyway!
👌 1