GoogleCloudPlatform / gradle-appengine-plugin

Gradle plugin that provides tasks for uploading, running and managing Google App Engine projects
Apache License 2.0
236 stars 60 forks source link

daemon + remote debugging : suspend support? #229

Closed renaudcerrato closed 8 years ago

renaudcerrato commented 8 years ago

I'm using Idea Intellij CE, and I'm struggling to setup a debug configuration: I'd like the development server to wait for my debugger to connect - but it seems the daemon property on appengine is not respected when suspend=y:

image

appengine {
    daemon = true
    jvmFlags = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000']
...

When I run the gradle task, using the setup above (suspend=y), the task never exits - which is probably because of the JVM waiting for the debugger. IMO, if daemon = true the JVM should be started from a forked process instead of detaching it from the JVM...

Am I missing something?

loosebazooka commented 8 years ago

I think I understand what you're saying. The jvm flags are used by the kickstart program that starts up the dev appserver process, see : https://github.com/GoogleCloudPlatform/gradle-appengine-plugin/blob/43b1115ff4338389d7d97538ddfb2ba66e895849/src/main/groovy/com/google/appengine/task/RunTask.groovy#L94 and https://cloud.google.com/appengine/docs/java/tools/javadoc/com/google/appengine/tools/KickStart

Yeah your problem is that backend:appengineRun will never exit in your setup. This is because the process launching kickstarter is trying not to move forward before the devappserver is up. I believe the original author's intention was to only move forward (specifically for functional tests) once the server was up and so there's some semaphoring going on there. There's not particularly a good way to deal with this without breaking the functionality of the appengineFunctionalTest task.

You can try creating a generic java run configuration that emulates what kickstart is doing and use that to launch your devappserver instead of the gradle runner.

It's not clear to me though why you want daemon = true on the dev_appserver though.

renaudcerrato commented 8 years ago

Thanks for the answer. Since i'm telling my debug configurations to run the gradle task appengineRun beforehand, I need daemon = true or the configuration will wait indefinitely for that task to end...

Didn't tried using a java task - but sounds like the only possible solution.

loosebazooka commented 8 years ago

Oh yeah of course. Your other option is two steps (two run configs launched one after the other)?

renaudcerrato commented 8 years ago

Yep, I tried this one, but the appengineRun as configuration didn't exit neither, probably because that's recognized as a gradle task...

Didn't succeed yet to find the correct options to run it as Java.

loosebazooka commented 8 years ago

I would do something like the kickstart page describes

https://cloud.google.com/appengine/docs/java/tools/javadoc/com/google/appengine/tools/KickStart

 java -cp <an_absolute_path>/lib/appengine-tools-api.jar \
   -agentlib:jdwp=transport=dt_socket,server=y,address=8000 \ <-- I think running in debug from the IDE will automatically do this for you
   com.google.appengine.tools.development.DevAppServerMain \
   --address=localhost --port=5005 <an_absolute_path>/appDir

appengine-tools-api.jar is in <user-home>/.gradle/appengine-sdk/appengine-java-sdk-1.9.XX/lib app-dir is in <project-directory>/build/exploded-app

renaudcerrato commented 8 years ago

Damned, I missed it! Many thanks for the directions!