How to set up IDEA to execute post compilation task? - intellij-idea

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.

Related

(Kotlin) Any workaround for annotation processing in Intellij IDEA

I've created a gradle modules main that contains main program logic and codegen that contains annotation definitions with processors. I found that:
Please note that kapt is still not supported for IntelliJ IDEA’s own build system. Launch the build from the “Maven Projects” toolbar whenever you want to re-run the annotation processing.
on kapt page (https://kotlinlang.org/docs/reference/kapt.html) but I really need it. May be there is some (may be ugly) workaround for that? Terminal background worker or prebuild tasks or something else?
P.S.
This can appear as duplicate question but I really didn't found working solution at the moment
At the current project we have this problem as well; we use gradle and the work around is to run gradle classes testClasses from the commandline - either in an external terminal program or in IJ's terminal (alt-F12 on macOS). This triggers kapt as well, and when this is done I do a Build/Rebuild project from IJ's menu as well.
This is enough if the code that is processed by kapt does not change too often (we just use mapstruct and querydsl).
If you are using maven a mvn compile test-compile should work as well.
Finally I found that repository that does work in Intellij IDEA without any workarounds (https://github.com/miquelbeltran/kotlin-code-gen-sample). Taken from https://medium.com/#Miqubel/hello-world-of-annotation-processing-in-kotlin-3ec0290c1fdd

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.

how to set up an automatic compilation of test classes?

Intellij idea not compiles special classes when running test. Now I run the compilation manually via activator console. How can I customize the intellij idea to run automatically when start a compilation of test?
I'm not sure if I got you right but you can try to right click your test class and choose "Run [your_class]". It will compile the needed classes.

Running test without compile in SBT - how-to

I'm new to SBT and I would like to know if it is possible to run tests without compiling. I mean to use a set of classes that have been already compiled.
Is this possible and what should I do to get this done?
sbt detects the available tests during compilation for efficiency. To run already compiled tests that are on the classpath and not in source files, it would be necessary to explicitly list them in the definedTests task. This isn't too straightforward, though.

Can I view the command line to be executed in IntelliJ

I am trying to diagnose an issue I am having with IntelliJ 10.0.2 not being able to launch a run configuration due to an (potentially) excessively long command line. It is an 'OSGI Bundles' configuration using the Equinox Framework.
I would like to be able to get the command line that Idea is trying to execute so I can diagnose the issue but I'm not sure how to.
The 'run' tool window does not open but a tooltip appears above the 'run' tool window tab stating that the command line is too long and that this could potentially be solved by enabling a classpath file. However 'dynamic.classpath' has already been enabled and is working (I can run my unit tests only with this set to true).
Any thoughts? Thanks
I don't use a CLASSPATH in the command used to launch an app in IntelliJ. I add all the JARs I need as libraries when I configure the module. If those are making your run command unnecessarily long, perhaps using IntelliJ as it is intended will sort you out.