Debugging SBT project with Play in IntelliJ IDEA - intellij-idea

I have a SBT project
in this project i have a sub play project and other projects
example from my build file :
lazy val subProj1 = Project(id = "sub-proj-1", base = file("sub1"))
.settings(...)...
lazy val subProjPlay = play.Project("play-proj", 1.0 , path = file("web"))
need to debug the play server from IntelliJ IDEA.
To run the project I use sbt run on the command line.
How can I debug the project in IDEA?

I found this to be the easiest solution : (using IntelliJ IDEA )
in IntelliJ :
Go to "edit run configurations"
Create a new remote configuration (port 9999, all other details leave with default values)
Go back to IntelliJ and run the new debug configuration (don't forget to put a break point)
From command line run :
sbt -jvm-debug 9999 run

The easiest solution.
Edit Configurations... -> add SBT Task (not Remote task).
Specify SBT Task: ~run.
Run created SBT Task using - Debug button

Provided you've Play distribution installed locally, use play debug run on the command line and connect to localhost on the port 9999 in IDEA.
From Debugging section in Using the Play console in the official Play 2.2.x documentation:
You can ask Play to start a JPDA debug port when starting the console.
You can then connect using Java debugger. Use the play debug command
to do that
If however you don't have it (and for a reason don't want to install it), add Remote Run configuration in IDEA that will give you a hint for the command line arguments you should be using when launching SBT, e.g.
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
When you launch SBT that may or may not be as simple as launching SBT jar, just use the above to configure JVM to run in debug mode.

IntelliJ IDEA 2016.1.1 && Play Framework 2.5.3
For me, no matter how I set(create new Run/Debug Configuration for Play 2 App or SBT Task, specify the debug port, execute in Run or Debug mode) in the IntelliJ IDEA 2016.1.1 Enterprise Edtion, the IDEA can not open the debug port(default 9999), so the debug is impossible.
After disable the sbt-fork-run-plugin(comment it in /project/paly-fork-run.sbt), it works!!!
I am newer to Play framework,and have found many bugs...Compare to RoR, it's so hard to learn, to run, to use, to debug...
Below is my steps:
disable the sbt-fork-run-plugin(comment it in /project/paly-fork-run.sbt)
execute activator -jvm-debug 9999 "run 11111" (I use port 9999 to debug, port 11111 to run my Play project)
In IDEA, add an new Run/Debug configuration, Choose, set debug port to 9999
debug the new created configutation

Related

sbt with intellij: debug mode doesnt work

I am trying to debug a sbt application in intellij, but somehow break points are not hit.
My steps:
On terminal, run:
sbt -jvm-debug 5005
Then create debug configuration:
Then hit debug button:
And finally run the app:
sbt:raptor> run
Application does run well, but none of the debug points are hit.
What am I missing here?
If it remains on the latest version of the IDE, please submit the issue in https://youtrack.jetbrains.com/issues/SCL .

Start IntelliJ run-configuration from command line

I work on a Kotlin-based cloud microservice. From time to time I need to run it in the IntelliJ debugger, but we often accidentally break the "local debug flow". There is no pipeline that checks if the IntelliJ run-configuration and the somewhat complex set of cloud-simulating proxies and mock-servers are in sync with the code base.
I would like to write a script that helps me check if the local debug flow works. The script should do the following:
build the project
start up the "mock cloud"
start the service locally using an IntelliJ run-configuration
run a Postman-collection against the locally running service
I need help with step 3 (and possibly step 1): How can I start the IntelliJ run-configuration via command line? I am using IntelliJ IDEA 2021.2 and MacOS 12.3.1.
There is no built-in way to start a Run Configuration from the command line. Instead, you should execute java/kotlin binary with classpath etc.
For example, for "Application" configuration it is needed to run the command like that:

Could not delete caches dir when compile Kotlin in Intellij IDE

My project use plugin kapt to generate mapper.
When run app then can not compile Kotlin (image below)
If remove plugin kapt then it not happend.
To resolve I must restart Intellij IDE. Take more time.
This error probably only happen on windows
This is a Kotlin bug, you can vote and watch it for updates: https://youtrack.jetbrains.com/issue/KT-36253. A workaround is to kill the running Java processes.
I have this problem almost every build (Android Studio stable + Artic Fox).
Manual Solution (try this first, if it works continue)
Task manager > Processes > End "OpenJDK Platform Library" tasks
(sometimes it's standalone, sometimes it's under "Android Studio")
OR
Task manager > Details > End "java.exe" tasks
Automated Solution
Create a new end-java.bat file
Content of .bat file: taskkill /f /IM java.exe
Right click end-java.bat file > create shortcut
Right click the shortcut > properties
Add shortcut key (e.g. ALT + CTRL + 1)
ALT + CTRL + 1 will now fix the issue
Try This :
https://developer.android.com/studio/build/build-cache
Add this code :
// To re-enable the build cache, either delete the following
// line or set the property to 'true'.
android.enableBuildCache=false
After that clean project and restart android studio
Also you can try to use a different JDK (e.g. OpenJDK). It helped me.
File -> Project Structure -> SDK Locations -> JDK Location
You can reboot the system, it will help. But this problem will return soon. This is the bag of Android Studio 4.2 https://youtrack.jetbrains.com/issue/KT-36253

How to run Play Framework 2.x in debug mode in IntelliJ IDEA?

I want to run Play Framework 2.x in debug mode in IntelliJ IDEA. I searched in the Internet and all results say that you have to use play console.
Is it possible to run in debug mode in IntelliJ IDEA without using play console?
Using activator :
From Terminal (Not intellij terminal), enter command : activator ui
Open your existing app
Choose "Code view & Open in IDE
In Browse Code, click setting icon
Choose Open Project in Intellij IDEA
Generate
Open Intellij IDEA
Open project - browse your app directory
Run - Edit Configuration
Add new configuration - Remote
Add name
Setting
transport : socket, debugger mode : attach, Host : localhost, port : 9999
module clashpath : your app
Tools - Open Terminal
activator -jvm-debug 9999 run
Run debug
Open browser localhost:9000
You need to use Idea 12+ Ultimate Edition
Install Play 2.0 Support, Scala and other required plugins in Idea
In command line perform play idea to generate project
Open created project in Idea (open, don't import)
Go to: Menu > Run > Edit Configurations... > Add New Configuration... > choose Play 2 App
In Menu > Run new buttons will appear Debug and Run, first will run app with enabled debbuger.
Preparation: Do not use the project creation by activator ui or similar. Just
open the project in IntelliJ.
activator -jvm-debug 9999 ~run. The ~ before run enables automatic reloading of generated HTML pages
In IntelliJ:
Run > Edit Configurations...
Select Defaults/Remote
Click on the green + at the upper left corner
Give the name "Play 2"
Ensure that Transport:Socket and Debugger mode:Attach are selected
Type in 9999 as port
Press "OK"
Run > Debug Play 2 (second entry in the list)
Pro hint: Check out the play-auto-refresh plugin to have Chrome automatically reloading on a change.
(based on #ARM's answer)
Open Intellij IDEA
Open project - browse your app directory Run - Edit Configuration
Add new configuration - Play2
Add http://localhost:9000 to url to open option
Add -Xms512M -Xmx1024M -Xss1M -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256M to JVM option
Set Debug port to 9999
Set your debug point and debug your application. Cheers :)
FYI : All of the above fields might filled up already
this works for me and maybe easier
file menue => settings => Build, Execution, Deployment => sbt => check "Enable debugging for sbt shell"
idea sbt shell now will start with debug enable, log out the port as "Listening for transport dt_socket at address: 52701"
Run/Debug Configurations => Add(the pluss(+) sign) => Remote => Set "Port" And "Use module classpath"
just type run in sbt shell, then click debug button
screent shot
enable idea emaded sbt debug
sbt shell start log
add remote in "Run/Debug"
type run here

How to debug a maven goal with intellij idea?

Can you debug a maven goal with Intellij IDEA? I know that I can right-click and run Debug. However, the maven plugin does not appear in my External Libraries list, so I can not go into the code and set a breakpoint. Thus, Debug runs through the goals without stopping, like Run does.
I am using OS X 10.8 and IDEA 12.0.2.
EDIT: Goal
I've written custom specRunner for https://github.com/searls/jasmine-maven-plugin - However, $specs$ stays empty. So I try to see which files are actually loaded.
Figured it out:
from the command line, run maven goal with mvnDebug instead of mvn. E.g. mvnDebug clean
Open the source of the maven plugin you want to debug in intelliJ and set a breakPoint
In IDEA, add a Remote JVM Debug Configuration.
Under Settings, set Transport: Socket, Debugger Mode: Attach, Host: localhost, Port: 8000 (default port of mvnDebug).
Run the Configuration in Debug mode. It should connect to the waiting mvnDebug jvm.
Very easy. I am using Intellj Idea 15.0.4
Set the breakpoint in your maven plugin
In the tag "Maven Projects" go to the project witch is using your maven plugin.
In "Plugins" find your plugin and over the goal right click and Debug
Here is a screenshot:
Old question, but I was having the same need and it took me a while to get it to work. Hopefully can help someone.
For test debugging use:
mvn <goal> -Dmaven.surefire.debug
or
mvn <goal> -Dmaven.failsafe.debug
When execution stops and listens to socket at address 5005 (default) you run your configured remote debugger.
How to configure it:
Run -> Edit configurations -> Remote
Transport: socket
Debugger mode: Attach
Port: 5005 (default)
-> Save.
I think the easiest solution is to temporarily add the maven plugin as a dependency. Once this is done, IntelliJ will treat this just like any other dependency and you can set breakpoints the usual way.
The easiest way to debug maven goal ONLY within IntelliJ is to create a regular maven goal and in the runner tab pass those VM options:
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
Where 8000 is a port number for remote debugging.
Then create new Remote configuration with port 8000. Run this configuration after running maven goal.
No need to setup up Java Remote Debugger or anything like that. It is literally just a right click -> debug on the Maven goal now, as explained in the official docs.
Either You can refer to above answer Or just add this plugin to pom.xml
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>
-Xdebug -
Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
</jvmArguments>
</configuration>
</plugin>
And run maven goal with mvn instead of mvnDebug. E.g. mvn spring-boot:run
In IDEA, add a Remote Configuration.
Under Settings, set Transport: Socket, Debugger Mode: Attach, Host: localhost, Port: 8000 (default port of mvnDebug).
Run as Debug in IDEA , whenever you want to debug the code.
Since you are working with Intellij, there is already a built-in debugger there and you do not need to necessarily use mvnDebug which is a command line tool. Check out this tutorial: How to Debug Maven Applications in Intellij IDEA.
The tutorial uses the Maven Exec Plugin and lets you debug the application without a need to use the command line or MvnDebug. Thought sharing it might be of value here.
#Peter Szanto 's answer work for me, but I don't like mess my source code.
And I can't make those MvnDebug way work.
So I try another way, add plugin source as IDEA module.
Here is the detail step:
Clone the plugin source as an independent project.
In your project, go to File -> New -> Module from Exist Sources and add the plugin project you clone in step 1.
Now you can open the plugin source code and set some break point.
Run your maven goal as debug mode, it should stop at the break point.