How to run sbt task on make project in IntelliJ IDEA? - intellij-idea

I'm working on a scalajs project. My workflow is: make code changes, make project in IntelliJ, go to sbt and run fastOptJS task to produce js file, go to browser and test. I would like to remove the step of manually running fastOptJS task in sbt and make that happen automatically when I make project in IDEA. Is there any way to do that?
UPD: It would be also nice to keep sbt running between fastOptJS calls, cause it takes time for sbt to start.

You can simply start the JavaScript compilation with the sbt watch mode.
Select Run | Edit configurations... and add a new SBT Task by pressing the green plus. In the field "Tasks:" define ~fastOptJS and then run the new configuration.
It will compile again whenever you have changed something.

This should be the workaround for your propose, instead of use "Make Project ( Ctrl + F9 )", you can create a run in IDEA and configure an external tool as the image shown, where you can run the fastOptJS task in sbt.

Related

How to set up IDEA to execute post compilation task?

When trying to run some code after compilation is finished, I wrote the following in my sbt build:
compile in Compile <<= (compile in Compile) map { x=>
// post-compile work
doFoo()
x
}
Which works well if I run sbt compile from command line, but doesn't get executed when I build from IntelliJ IDEA.
Is there any way to have IntelliJ IDEA run my post compilation step?
Looks like the only way IntelliJ IDEA supports is via Ant, unfortunately.
See VS post build event command line equivalent in IntelliJ IDEA?.
Also, if you go down this route, you might be interested to use ant4sbt.
IDEA has Run/Debug configurations.
In the Before Launch option, normally we have Make as the default action.
It is a matter of simply adding a Run external Tool action after Make. We can define any number of actions.
The external tool could invoke SBT.
Or we can remove Make and call SBT to handle all the process. The only inconvenience of this, is that is a little less confortable to go to syntax errors when compiling.

IntelliJ 14 Gradle task in Test Runner

Upgraded to IntelliJ 14.0.1 One of the big new features I was looking for:
"If you run tests via a Gradle task, the IDE offers you the standard Test Runner instead of the console output." (Source: https://www.jetbrains.com/idea/whatsnew/#buildTools)
I right click on the Gradle Task to run our Integration Tests:
However, I see the results of the test still going to console output, not to the Test Runner:
Has anyone been able to get this new feature in IntelliJ IDEA 14 to work?
Thank you in advance,
Philip
Looks like IntelliJ looks for a task named "test" rather than a task of type Test.
https://github.com/JetBrains/intellij-community/blob/master/plugins/gradle/src/org/jetbrains/plugins/gradle/execution/test/runner/GradleTestsExecutionConsoleManager.java#L191
Rename the test task to unitTest and then create a wrapper that runs both:
// Rename test to unitTest
tasks.test.name = "unitTest"
// Wrap and run both
task test(dependsOn:['unitTest', 'integrationTest'])
If you only want to run integration tests, just overwrite it:
task test(overwrite: true, dependsOn: ['integrationTest'])
This allows me to run the integration tests in the test runner successfully (at least it works in IDEA 15 EAP but it should work in 14 as well I would think).
I still get this in IntelliJ 2017.1, but specifically when running tests in the gradle buildSrc directory. After digging a while, it turns out that the Gradle API doesn’t expose the test tasks in the special buildSrc directory to Intellij, so IntelliJ doesn’t recognize it as a test.
Workaround: Open another IntellIJ project for the buildSrc directory directory instead of trying to run tests cleanly inside the root project.

How to run sbt-assembly tasks from within IntelliJ IDEA?

Is it possible to run sbt-assembly from within IntelliJ IDEA?
Also I read in the doc that one could add task within the SBT Tool window. But what I see is that it only helps you view your project not task? I cannot add any tasks there. How does the Tool window work exactly?
I have the last version of IntelliJ IDEA.
You can find the SBT plugin useful for your needs. With it, you can execute any tasks or command available in your build so sbt-assembly ones should work, too.
The plugin gives you SBT Console in which you start a sbt shell as if you were running it on the command line. The plugin gives you a more IDEA-like environment to work with the interactive console.
This answer is now out-of-date.
IntelliJ now allows you to create a run configuration for an SBT task. You create the Run Configuration by :
choosing "Edit configurations" from the "Run" menu (or the toolbar
popup)
click the "+" button to add a configuration and select
"SBT Task" as the type of configuration you want to make.
fill out the details such as the name of the task and the
working directory if necessary
You can now run the task in the same way as any other run configuration; select it in the run configuration popup in the toolbar and click the run button (or if you're one of those keyboard-only people press shift-ctrl-r and select the task from the popup that appears)
official documentation here : https://www.jetbrains.com/help/idea/2016.2/run-debug-configuration-sbt-task.html

SBT just loops in IntelliJ IDEA on SBT:Compile

Using Intellij IDEA 12.1.6 and SBT 0.13.0
I generated the hello-play with Activator and generated IDEA project. If I compile using the SBT console it both compiles and runs fine. If I create a run configuration with a Before launch: Run SBT Action 'compile' and launch, I just get the spinning Executing SBT Action and it never stops. I finally close IDEA.
Am I missing something basic here?
Here you can have the explanatioin of why this won't be fixed:
https://github.com/orfjackal/idea-sbt-plugin/issues/66
Instead you may just kill SBT (a small skull icon on the left pane), this will remove all those "Executing SBT Action" processes.

Intellij IDEA: multiple goals, multiple projects, one button

I find myself often running the same goals (clean install) of different, interdependent maven projects in Intellij IDEA one after another.
Does anyone know of a way to configure something like a maven goal combination, ideally such that you configure a button in IDEA's task bar that you can hit to execute these goals in sequence? Possibly even with a keyboard short cut?
Similar things might be achieved with a maven run configuration, but then IDEA wouldn't automatically be aware of the changes the run does to the project's file system resources.
Cheers,
Johannes
Easy solution for me was to create a Run Configuration (type=Maven) per module, putting multiple goals (e.g: clean install) as cmd line for each of them, then linking them up into a chain, by adding an appropriate one under the "Before launch" section.
You can link up the last of the chain as a "Before launch" for the actual app Run.
Then you can, if required, just restart a running instance if your app which will rebuild your maven projects in order, and start the app again.
I frequently run a clean install of my maven aggregator project from the command line while it is open in IntelliJ. In my experience the IDE seems to handle this quite well.
when you open the MVN - 'Run Anything' appears - beside that there is a PROJECT drop down, from which you can select for which project you want to run the maven command.