从IntelliJ调试Grails应用程序

Dón*_*nal 5 debugging grails intellij-idea

我一直在努力从IntelliJ内部调试Grails 2.5.0应用程序.具体来说,我发现很难配置应用程序

  1. 功能测试可以调试
  2. 可以运行功能测试
  3. 该应用程序可以调试
  4. 该应用程序可以运行

从IntelliJ(版本14.1.4)中启动(1)和(2)时.

这是我用来调查这个问题的玩具Grails应用程序,它有一个功能测试.调试工作的关键似乎是这些JVM分支设置BuildConfig.groovy.

grails.project.fork = [
        // configure settings for compilation JVM, note that if you alter the Groovy version forked compilation is required
        //  compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm: 256, daemon:true],

        // configure settings for the test-app JVM, uses the daemon by default
        test   : [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, daemon: true, jvmArgs: jvmArgs],
        // configure settings for the run-app JVM
        run    : [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve: false, jvmArgs: jvmArgs],
        // configure settings for the run-war JVM
        war    : [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve: false],
        // configure settings for the Console UI JVM
        console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
]

// Include the line below to debug functional tests from IntelliJ. The tests should be launched in Debug mode from IntelliJ
//grails.project.fork = null
Run Code Online (Sandbox Code Playgroud)

调试run-app(3)

启用分叉后,可以通过从IntelliJ内部运行应用程序来调试应用程序,然后从IDE启动远程调试器以连接到端口5005上的应用程序.JVM分叉设置可确保应用程序始终在启用远程调试的情况下运行,因此一定要通过运行它来启动应用程序,而不是调试它.

调试功能测试(1)

要调试功能测试,您需要包含此行

grails.project.fork = null
Run Code Online (Sandbox Code Playgroud)

这样就分叉了(并且禁用了远程调试.然后你可以通过IntelliJ调试配置启动测试来调试功能测试.

根据是应用程序还是正在调试的功能测试,必须包含/注释掉这一行是相当繁琐的,所以我正在寻找一个更简单的解决方案.

有人可能会认为这可以避免

if (Environment.current == Environment.TEST) {
    grails.project.fork = null
}
Run Code Online (Sandbox Code Playgroud)

但由于某些未知原因,这不起作用.

小智 5

我有以下设置BuildConfig.groovy

grails.project.fork = [

    // configure settings for the test-app JVM, uses the daemon by default
    test: false, // see http://youtrack.jetbrains.com/issue/IDEA-115097
    // configure settings for the run-app JVM
    run: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
    // configure settings for the run-war JVM
    war: false,
    // configure settings for the Console UI JVM
    console: false
]
Run Code Online (Sandbox Code Playgroud)

您需要在 intellij 中添加 2 个运行配置:

  • 为您的 grails 项目添加一个新的运行配置。使用run-app --debug-fork的命令行。
  • 添加新的远程调试配置。只需使用默认设置。

要调试您的应用程序,请运行第一个配置。grails 应用程序将启动并打印Listening for transport dt_socket at address: 5005。看到此消息后,请运行调试配置...

如果您需要屏幕截图,请告诉我