SBT just loops in IntelliJ IDEA on SBT:Compile - intellij-idea

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.

Related

Intellij Command Used for "Refrsh SBT Project"

I'm wondering what is the actual sbt command that Intellij is executing when I use "Refresh sbt project" from the sbt window. I would like to understand how the same command can be issued from the sbt shell.
The IntelliJ Scala plugin ships with the sbt-structure sbt plugin, which gets automatically loaded with sbt shell sessions that you start from the IDE. When you enable sbt shell for imports, a refresh simply writes commands similar to these to the sbt shell:
> set org.jetbrains.sbt.StrcutureKeys.sbtStructureOptions in Global := "prettyPrint download"
> */*:dumpStructureTo structure.xml
To actually import the project structure, IntelliJ also runs an additional step which does not happen in sbt.

How to run sbt task on make project in 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.

IntelliJ 14 + gradle issue with system properties in test

This is snippet from my build.gradle file:
test{
systemProperty "test", "test"
}
Then I have my test code which looks like this:
#org.junit.Test
public void test(){
Assert.assertEquals("test", System.getProperty("test"));
}
And when I run this test from command line it is passing. If I choose in gradle window task test and click right mouse button and then select run this test also pass. However when I go to test itself and select run on method name it does not pass. It looks like in the third case IntelliJ completely ignored gradle context. Is there something that can be done to make this test work when running directly from IDE? Thanks in advance for reply. Gradle version 2.3.3 and IntelliJ 14.0.2
IntelliJ doesn't currently understand such configuration. To fully solve this category of problems, IntelliJ will need to use Gradle as its underlying build/execution engine, like Android Studio already does today. Until this happens (or support for this specific use case is added to IntelliJ), you'll have to define the same system property in the IntelliJ run configuration (template).
If you use the IntelliJ project generation approach (gradle idea), you can (with some effort) make Gradle generate such a run configuration (template). This is something we do for Gradle's own build.
For IntelliJ you need to add your System Property -Dtest=test to Gradle VM options within Settings > Build, Execution, Deployment > Build Tools > Gradle

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.