Debugging revel with IntelliJ - debugging

How can we configure IntelliJ to debug revel apps?
In Run/Debug Configurations, it's not at all obvious what to enter for File, Go tool arguments, and and Program arguments

Create your project, for this example i will be using canonical revel new github.com/myaccount/my-app
Run in terminal revel run github.com/myaccount/my-app to generate tmp/main.go - this file is needed by intellij
Select "Edit configuration" to create Run configuration. Select Go Build
Select YOUR file "main.go"
Paste in "Program arguments" string -importPath github.com\myaccount\my-app
Click on "Before launch: ..." and create "Run external tool"
There: Program: <your gopath>/bin/revel(Windows - revel.exe) Paramerets: build github.com/myaccount/my-app, Working dir <your gopath>/bin
Screenshot Example Config
Now You can Run and Debug in panel IntelliJ

Related

Running GUI apps in Goland IDE

When I build in Terminal, I can use a flag to say I want to build for GUI:
go build -ldflags="-H windowsgui"
However, I just started using JetBrains Goland and I don't how to run GUI apps. What can I do?
go build will only build the application.
To actually run the application, you should go to Run | Edit Configurations... | + | Go Application and configure the application as you need.
Here you will need to set two options:
add -ldflags="-H windowsgui" to the Go tool arguments option
configure the Output directory to be in the same directory as your .manifest file
Setting the output directory is critical in order to run the the application without encountering the following panic panic: TTM_ADDTOOL failed described in this issue.
Then you can run the configuration via Run | Run... and select the configuration you've just created.

How to run/debug a beego app using Gogland (go language)

Im using Gogland (IDE from JetBrains. Version 1.0 Preview/EAP Feb, 10 2017) to create a Beego web app.
I can run it from command line with:
bee run
and everything works.
However if I run it from the IDE with the following configuration
when I go to localhost:8080 it says it can not find the template file in path:
I thought it was related to GOPATH, but then I realized that Gogland IDE is probably running
go run main.go
instead of
bee go
and when I checked runing
go run main.go
from the shell, I got the same issue: cant find the template.
I even tried to run the 'bee' command from the IDE. I partially succeed. With this configuration:
I can run it from the IDE, but the debugger doesn't stop in any breakpoint. IE: I can only run (but not debug) it, from Gogland.
So my question is how to make gogland IDE debug a beego project
Use Delve and Remote Debugging Configuration(start from gogland eap9).
Run your bee app like:
bee dlv -package="app_name" -port=2345
On gogland make configuration Go Remote with port which you set previous.
You cannot change the IDE to run the bee command. However, you can change the run configuration to a Go Application by going to Run | Edit Configurations | + | Go Application select the package type then type the full package name (github.com/dlsniper/demo for example if your package main is under GOPATH/src/github.com/dlsniper/demo) and make sure the working directory is where you need it to be. Hope it helps.
I resolve this by setting:
beego.BConfig.WebConfig.ViewsPath="/Users/xxxxx/go/src/xxxxxxx/views" // your views directory
by the way: if you have staticpath , you should also use absolute path.
eg: beego.SetStaticPath("/static", "/Users/xxx/go/src/xxxx/static")
it's only used when debug, if you publish your program, you should remove this hard code config.

IntelliJ & Maven - mvn command not found

I'm trying to build a drop wizard project created with IntelliJ.
when I run
mvn package
I get
bash: mvn: command not found
I'm on a Mac and I'm following this tutorial: http://www.dropwizard.io/0.9.2/docs/getting-started.html
According to IntelliJ documentation (https://www.jetbrains.com/help/idea/2016.1/maven.html?origin=old_help)
Maven integration is shipped with IntelliJ IDEA, and you do not need to perform any additional actions to install it. You can start using it straight away for importing Maven projects, working with them and for running Maven goals.
So I don't know what I'm suppose to do in order to use the command line
Any idea?
Thanks
In IntelliJ, on the right hand side, click "Maven", and expand "Lifecycle"
Select "Package" and click "Run" (green arrow).
mvn is the command line tool for Maven.
See https://maven.apache.org/install.html for details on how to install it.
Or as you are using a Mac if you use brew try using it to install the maven formula.
If you have maven properly installed and you want to configure intelliJ terminal with a custom Terminal or if you want fix "command not found",
follow these steps:
Click > File
Click > Settings
Click > Tools
Click > Terminal
Edit "Shell path" # "Application Settings", if you use git bash change current path with:
C:\Users\Work\AppData\Local\Programs\Git\bin\sh.exe --login
// The path you may have differs based on your OS, in example: "installationPath\Terminal Folder\bin\sh.exe --login"
Click > Apply
Click > Ok
I used git bash but technically it should work with every terminal. Do not forget to add --login after the *.exe
If it still doesn't work maybe you need to check:
Click > Environment variables
Click > System Properties
Click > Environment Variables
Click > System Variables
Select > Path from the list
Click > Edit
Click > New
Insert the path of your maven bin folder, in example:
"installationPath\apache-maven-3.8.6\bin"
Also insert the path of your jdk, in example:
"installationPath\Java\jdk-18.0.1.1"

How can I make "gradle --stacktrace" the default?

Is there a way I can set --info or --stacktrace via gradle.properties?
I currently have a gazillion build scripts that end up invoking gradle at some point, and I would like to standardize the error handling behavior across the board.
Not in gradle.properties but in build.gradle itself. Add the following piece of code at the very beginning of the build script:
import org.gradle.logging.ShowStacktrace
gradle.startParameter.showStacktrace = ShowStacktrace.ALWAYS
throw new RuntimeException('lol')
Or in Android Studio:
import org.gradle.api.logging.configuration.ShowStacktrace
gradle.startParameter.showStacktrace = ShowStacktrace.ALWAYS
It also might be put in init script.
As pointed out in the comments, from gradle v. 2.14 it will be:
gradle.startParameter.showStacktrace = org.gradle.api.logging.configuration.ShowStacktrace.ALWAYS
There is another approach where you do not have to edit the build.gradle file because you may not want it so verbose when you run your CI. In addition, you now have to remember to turn it off in CI. So, instead, you can limit to the IDE. If you are using eclipse, you can follow these steps to apply it only to gradle runs within your IDE.
Run -> "Run Configurations" -> Select "Gradle Project" -> Click "Project Settings" tab -> Click "Configure project settings..." link -> Select "Override workspace settings" -> paste "--stacktrace" in "Program Arguments" text field.
The above worked with Spring Tool Suite 4.2.1 which is based on Eclipse 4.11.0.x
Since Gradle 7.4 this is possible through gradle.properties.
org.gradle.logging.stacktrace=all
Docs: https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties
Added in https://github.com/gradle/gradle/pull/18713

applying mvn commands via intelliJ IDEA

How to run following mvn commands via intelliJ IDEA? I can run these commands from terminal but how to do the same in the IDE for the project opened in it?
--mvn clean dbmaintain:updateDatabase
--mvn clean package
Go to "Edit Configuration" and create a new "Maven Run/Debug Configuration". There you can define the command line and the working directory.
An other way of doing the same is : open de maven projects view (on right edge of the window) expend your module, expand the "Life-cycle", select the phase you need to run. Then a simple rigth click shows a popup allowing you to "run" the phase or create a run configuration preconfigured with the working dir and the phase. (you can always edit it)

Resources