Execute Run/Debug Configuration on save - intellij-idea

I have a Run/Debug configuration in Intellij IDEA. It simply runs cargo check for my Rust project.
I'd like that configuration to run every time I save a file in my project.
I've investigated the File Watcher and Save Actions plugins and I don't think they support this.

Related

Use custom script in Intelij IDEA to run sbt shell

Is it possible to run sbt shell in Intelij IDEA using custom script instead of built in sbt or sbt from sbt-launch.jar? Why I need this, for example there is some project which uses custom script to set config file location, VM parameters, and other options for sbt and this script is shared in version control system. And it would be very convenient to just specify for IntelliJ IDEA location of such script.
This is currently not possible. However, to pass project-specific sbt command line parameters to sbt you may place a .sbtopts in your project directory, and likewise a .jvmopts for VM parameters.

How do I make IntelliJ create Mocha debug configs when running unit tests?

When I create a new Mocha test file I am presented with the expected green gutter icons (▶ and ▶▶) to run each test or the suite. When I select "Run [test name]" I expect it to create a Mocha debug configuration and run it. Instead, IntelliJ creates a NodeJS run configuration, which understandably explodes in a shower of bit-flavored WTF.
If I manually create a configuration for the whole file, everything works as expected, including individual tests afterward. I am hoping that there is a setting somewhere that I have overlooked, something like "Settings -> ... -> Default Debug Configuration".
Does anyone know how I can make IntelliJ default to Mocha when a unit test is executed?
The logic used for determining what test runner is available for a given test file is based on dependencies declarations in package.json nearest to current file. Do you have 'mocha' listed as a dependency/dev dependency in your package.json? How many package.json files do you have in your project?
Note that, if Mocha is not installed locally/included in package.json, you can create a Mocha run configuration with "All in directory" selected and specify a directory where your spec files are located. In this case, clicking the gutter button in a test file inside this directory will suggest to run test with Mocha.
Note also that if you have created Node.js Run configuration with "JavaScript file" set to your mocha test file, IDEA will suggest using this configuration instead of Mocha when clicking on your tests, because explicitly created run configurations associated with current file have priority over the ones auto-generated from context. Deleting the configuration should solve the issue.

Intellij and sbt: How to make intellij to read custom configuration file for my play application tests?

For my test (Play Framework 2.6 app) I want to use different configuration file.
For this, I've added the following line into build.sbt
javaOptions in Test += "-Dconfig.file=conf/application.test.conf"
When I run tests from sbt (sbt test), it works fine, reads the custom configuration file.
But when running tests from IntelliJ IDEA, it ignores this setting and uses application.conf file.
How to force IntelliJ to use this sbt setting?
You have to edit your intellij configurations.
To do that use this : https://www.jetbrains.com/help/idea/creating-and-editing-run-debug-configurations.html.
Once you're in the edit configurations page, add ScalaTest into the list of your configurations. Then add -Dconfig.file=conf/application.test.conf under VM Parameters.
Save, and done!

setting classpath for gradle task / runconfig in intellij

I'm running unit tests in Intellij 14.1.2 with the Gradle plugin. I have external config and test data that is in environment specific in a set of directories (directory for each env). I want to load the config and data via the classpath.
In Eclipse I'd just add the env specific path to the run-config and save the config as:
'Test-XYZ-UAT1'
for example.
In intellij, it seems my application config classpath is tied to my 'module' classpath:
https://www.jetbrains.com/help/idea/2016.3/run-debug-configuration-application.html
how to add directory to classpath in an application run profile in intellij idea?
..which is bad enough but for the Gradle run configs I don't even have the option to add the module classpath.
Run/Debug Configurations window has no:
'Use classpath of mod...'
section.
Question:
How can I set the classpath of the run config when running a Gradle Task within Intellij ?
..and if someone could tell me how to get application run config specific classpaths setup that would be even better.
(please tell me I'm missing something ingenius about Intellij..)
Based on quite a bit of research and trial and error, here is the solution that works for my Kotlin based Spring Boot project.
Background:
My Spring Boot project run configuration is configured to use Run Gradle task in place of the standard IDEA build as its Before launch configuration (see screen shot below).
My Spring Boot project uses src/main/resources/application.properties for JPA and logging properties.
gradle build uses the following output directories for the build. These are the default gradle build output directories for a Kotlin project.
build/classes/kotlin/main for the main class files.
build/classes/kotlin/test for the test class files.
build/resources/main for the main resource files. This is where application.properties is copied during a build.
When I attempted to run this project inside IDEA using the run configuration above, it would fail during Spring Boot start up because it could not find application.properties inside the classpath. When I inspected the classpath used during application startup, build/resources/main was missing.
My Solution
Use the information from: Gradle Goodness: Delegate Build And Run Actions To Gradle In IntelliJ IDEA to delegate IDEA build and execution to Gradle.
When IDEA is configured to delegate build and execution to Gradle, the main and test modules should be configured as follows: On the Paths tab, select Inherit project compile output path.

Can I commit and share VM options in IntelliJ?

To execute my application, or run or debug unit tests, I need to enable various VM options, include -javaagent:<aspectjweaver-path> or -Djava.library.path=<some native lib path>
I can see how to change these configurations manually in IntelliJ IDEA under "Edit Configurations..."
What, if anything, do I need to check in to my VCS to share these settings with other members of my team, and ensure they pick them up automatically whenever someone changes them in the VCS?
Alternatively is there a way to set these automatically in IntelliJ without even touching the edit configurations? Especially the aspectjweaver. When I build/test my project from the command line using maven this is all handled for me by specifying argLine arguments to the surefire plugin, but IntelliJ doesn't respect these settings. Perhaps there are alternative plugins that can help me out?
First, you need to share your run configuration. It's simply done by checking the Share box right to the configuration name in the run configuration dialog:
Your run configuration will then be saved to .idea/runConfiguration (or whatever your settings folder name is).
From Jetbrains Web Help:
If this check box is selected, the run/debug configurations become available to the other team members.
The shared run/debug configurations are kept in separate xml files under .idea\runConfigurations folder, while the local run/debug configurations are kept in the .idea\workspace.xml.
This field does not appear for the default run/debug configurations.