build.gradle
gretty {
port = 8081
servletContainer = 'tomcat8'
contextPath = '/'
afterEvaluate {
appStartDebug {//修改debug时的监听端口,默认使用5005端口
debugPort = 9999 //此处填写端口号,如8080,如果修改端口号,则IDEA中的Remote 调试工具中需要填写相同的端口
debugSuspend = true
}
}
}
Import web-application into IntelliJ IDEA
Add apply plugin: 'org.akhikhl.gretty' to your project.
Import project into IntelliJ IDEA. Make sure you select "Import project from external model", "Gradle" in "Import Project" dialog.
Prepare "Remote Debug" configuration
Select menu "Run/Edit Configurations".
Check: "Run/Debug Configurations" dialog pops up.
Click on "+" icon, select "Remote" from the list.
Check: new configuration with name "Unnamed" appears under "Remote" category.
Change configuration name to something more sensible, like "Remote Debug".
Don't change any other parameters, just click "OK".
Run web-application under the debugger
Start gradle task "appStartDebug" under IntelliJ IDEA.
Attention: do not try to start this task under the debugger. Run it in normal mode.
Check: you should see "Listening for transport dt_socket at address: 5005" in "Run" output window.
Select menu "Run/Run...", select "Remote Debug" configuration, select "Debug" command.
Check: you should see "Connected to the target VM, address: 'localhost:5005', transport: 'socket'" in "Debug" output window.
Check: you should see "Run 'gradle appStop' to stop the server." in "Run" output window.