I am using Stack to setup, build, and run my Haskell projects from the command line. I want to use IntelliJ as my IDE but am running into problems configuring Stack as my build tool.
I used Stack to create and run a "Hello, World" Haskell program on the command line following the instructions in the Stack User Guide. Everything worked fine.
I have the HaskForce plugin installed on IntelliJ. The Build, Execution, Deployment -> Compiler -> Haskell Compiler tab gives you a choice between building with Stack and building with Cabal. I selecte Build with stack and configured it like so.
I can run the project using a Haskell Stack Run configuration. The console output is correct.
/Users/williammcneill/Library/Haskell/bin/stack exec hellohaskell-exe --
Hello, Haskell.
However, I cannot figure out how to rebuild the project through the IDE. For example, if I change the output text and rerun the program, I still see the original "Hello, Haskell" output. Build -> Make Project | Make Module | Rebuild Project all do nothing.
The Project Settings->Artifacts tab has nothing listed, and I don't see a way to add a Haskell executable here.
My workaround is to build my Haskell programs from the command line even when I'm editing from the IDE.
(It also looks strange to me to specify a path to a project-specific stack.yaml
file in the general Haskell compiler settings, but that was the only way I could see how to use Stack to build.)
How do I set up IntelliJ to build Haskell projects using Stack?
ghc 7.10.3, stack 1.1.2, HaskForce 0.3-beta.33, IntelliJ IDEA Ultimate 2016.1.3, OS X 10.11.5
This is Haskforce issue 282.
If you want to hit the IntelliJ run button to run the project and use Stack, I think you should use the IntelliJ Haskell Plugin as @mrek said. The HaskForce plugin says at the moment
Note: Run configurations are not supported for stack at the moment. This is for cabal projects only.
The install instructions for everything (from installing Stack to project setup) are in the readme, but I needed to change it slightly so I put my version here.
Installation instructions for everyone who wants to use Haskell
stack install hindent
and stack install stylish-haskell
(this can take a while).C:\Users\username\AppData\Roaming\local\bin\stack.exe
or /usr/bin/stack
) and Set Default (if it is not already default).
app/Main.hs
. You could replace everything in it with main = putStrLn "Hello Haskell!"
.You can start up the interactive console by clicking Terminal at the bottom of IntelliJ and then running stack ghci
. When you type main
you are calling main, and so on.
You could also use stack test
instead of the test run configuration.