Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug the AppEngine local server from IDEA+Gradle?

I'm following the Udacity App Engine course but as the tinker, I'm following using Gradle and IDEA (Open Source edition).

I have setup the project successfully using the following build.gradle file

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.google.appengine:gradle-appengine-plugin:1.9.7'
    }
}

apply plugin: 'war'
apply plugin: 'appengine'

sourceCompatibility = 1.8
version = '1.0'

appengine {
    daemon = true
    downloadSdk = true

    appcfg {
        oauth2 = true
    }
}

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
    appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.7'

    compile 'com.google.inject:guice:3.0'
    compile 'com.googlecode.objectify:objectify:5.0.3'
    compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.7'
    compile 'com.google.appengine:appengine-endpoints:1.9.7'
    compile 'javax.servlet:servlet-api:2.5'
    compile 'javax.inject:javax.inject:1'

    testCompile 'junit:junit:4.11'
    testCompile 'com.google.appengine:appengine-testing:1.9.7'
    testCompile 'com.google.appengine:appengine-api-stubs:1.9.7'
}

I am running the local dev server from IDEA using a Gradle run configuration with the appengineRun configuration and stopping it using another task for appengineStop. This is working, but I have no ability to debug as the breakpoints I put are not hit.

I believe this issue with breakpoints is because IDEA has no idea (I am horrible at puns) that it has to hook into the jetty server that backs the AppEngine server, but this is a wild shot as I have no knowledge of IDEA's internals, much less of how it handles Gradle executions.

How can I regain breakpoint ability? Is it feasible without a custom plugin?

like image 280
Machinarius Avatar asked Jul 24 '14 18:07

Machinarius


People also ask

How do I debug a Gradle project with appengine?

Configure debugging on a development server. Create Run/Debug configuration for Gradle. Select Run > Edit Configurations. Click + Add New Configuration. Select Gradle. In the Gradle project field, select the module where you configured the appengine-gradle-plugin plugin. In the Tasks field, enter appengineRun. Click OK.

How do I run a Gradle configuration?

Specify a name of your configuration in the Name field to quickly identify it when editing or running the configuration, for example, from the Run popup Alt+Shift+F10 or the Gradle tool window. Specify where you want your configuration to run on.

How to create a Gradle project in IntelliJ IDEA?

However, if you are creating a run configuration from the Gradle tool window, IntelliJ IDEA will display the name of your project automatically. You can also click Gradle registered projects icon to select an available Gradle module from the list of registered Gradle modules in your existing IntelliJ IDEA project.

How do I debug a Java app in IntelliJ?

Select Run > Debug. In the dialog, click Google App Engine Standard Local Server. After the project builds, you can set breakpoints to debug your app. IntelliJ Community Edition does not provide built-in support for running local Java servlet-based applications.


2 Answers

First you have to set the JVM debug parameters in your build.gradle file so that you are able to debug the local development server remotely.

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

Then you need to create a run/debug configuration in IntelliJ IDEA (based on the above parameters) to be used for remote running or debugging processes. Remote running/debugging enables you to connect to a running JVM.

You can find more details here. But basically go to the Run / Edit Configurations..., in the dialog box click on Add New Configuration (+) and select Remote. Make sure that the configuration matches JVM flags (especially port). Save and close the dialog box.

Start your local development server and connect debugger (Run / Debug).

like image 140
pgiecek Avatar answered Oct 23 '22 14:10

pgiecek


Configuration

Put jvmFlags on build.gradle

  appengine {
        run {
            jvmFlags = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000']
        }
    }

Debug

  • On Gradle execute appengineRun and wait to server start
    • Select Run \ Attach to process... to attach to the server and debug
like image 37
mabg Avatar answered Oct 23 '22 16:10

mabg