从 IntelliJ 调试 Grails 应用程序

2024-04-22

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

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

当 (1) 和 (2) 从 IntelliJ(版本 14.1.4)内部启动时。

这是一个玩具 Grails 应用程序 https://github.com/domurtag/multi-col-constraint-bug我正在用来调查这个问题,它有一个功能测试。调试工作的关键似乎是这些 JVM 分叉设置BuildConfig.groovy https://github.com/domurtag/multi-col-constraint-bug/blob/master/grails-app/conf/BuildConfig.groovy#L17L32.

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

调试运行应用程序 (3)

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

调试功能测试(1)

要调试功能测试,您需要包括这条线 https://github.com/domurtag/multi-col-constraint-bug/blob/master/grails-app/conf/BuildConfig.groovy#L32

grails.project.fork = null

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

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

人们可能认为这可以避免

if (Environment.current == Environment.TEST) {
    grails.project.fork = null
}

但由于某种未知的原因,这不起作用。


我有以下设置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
]

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

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

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

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从 IntelliJ 调试 Grails 应用程序 的相关文章

随机推荐