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

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!

Related

Execute Run/Debug Configuration on save

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.

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.

How to set environment vars in IntelliJ for Gradle tasks

the easiest way to pass spring profiles to gradle bootRun is (for me) by environment variable (e.g. SPRING_PROFILES_ACTIVE), when run on commandline.
Unlike the Application configurations, the config for gradle tasks does not provide an input for environment variables. And as VM options don't get picked up either as it seems, I can not run those tasks from the IDE.
I am aware, that I could start IntelliJ with the envvar set, but this seems rather cumbersome.
So what I need is the IntelliJ pendant for SPRING_PROFILES_ACTIVE=dev,testdb gradle bootRun, unless there is a good reason, they have left this out.
System is linux, intellij 14. The project in question is using springboot and I want to move over from running main in IntelliJ to running with springloaded+bootRun and separate compileGroovy calls as IntelliJ is not "understanding" the gradle file completely and therefor hides errors.
Make the System.properties available in the bootRun (or other) tasks.
bootRun.systemProperties = System.properties
This way we can set in IntelliJ VM Options like -Dspring.profiles.active=dev.
Here is my solution for setting up Spring environment variables / settings with Gradle / IntelliJ
Firstly, define a basic properties file, and then one based on your environment, such as:
#Configuration
#PropertySources(value = {#PropertySource("classpath:default.properties"),#PropertySource("classpath:${env}.properties")})
Int the above example, pay careful attention to the #PropertySource("classpath:${env}.properties"). This is an environment variable being pulled through.
Next, add a VM argument to IntelliJ (via the Gradle Tasks Run Configurations) - or as an argument via the gradle command line.
Lastly, copy the properties across in the gradle task as #cfrick mentioned and #mdjnewman have correctly shown:
tasks.withType(org.springframework.boot.gradle.run.BootRunTask) {
bootRun.systemProperties = System.properties
}
I've had success adding the following to my build.gradle file:
tasks.withType(org.springframework.boot.gradle.run.BootRunTask) {
systemProperty('spring.profiles.active', 'local')
}
This allows gradlew bootRun to be run from IntelliJ without requiring any changes to the IntelliJ Run/Debug Configurations (and also from the command line without having to manually specify a profile).

What is the command line option to pass into the activator framework to generate an intellij project?

I'd like to generate the intellij project files from a typesafe activator project via a script - is there a command line interface or command i can use for this purpose?
(i wasn't able to find directions for one online, or in the usual help locations)
Please note that since IntelliJ IDEA version 13 it is no longer necessary to generate files for IntelliJ IDEA. sbt support is now build in, you can open/import the project by opening your build.sbt with IntelliJ IDEA: http://blog.jetbrains.com/scala/2013/11/18/built-in-sbt-support-in-intellij-idea-13/
Remember that Activator is just an sbt wrapper with optional UI mode. So what you want is sbt-idea:
https://github.com/mpeltonen/sbt-idea
The Activator UI will auto-add this plugin and then (on the Code tab) it has an "open in" menu item to generate the intellij project.
If you want to script it, there are two steps:
add the plugin (either drop an idea.sbt in project/ directory or put it globally in ~/.sbt/0.13/plugins)
run activator gen-idea

Launching PHPUnit in PHPStorm for a single instance

I've seen a lot topics about PhpStorm, but they actually got me more confused than I was before.
Basically, my file structure looks like this:
http://i.stack.imgur.com/1nFE2.png
(This is from the Yii 1.1.13 Demo App "Blog")
Now what I want to do is to have these two options:
Choose any of these files -> Right click -> Run (as PHPUnit).
bootstrap.php and phpunit.xml have to be loaded somehow, because
these specify where to load the (Yii) classes needed.
run all tests
within a directory (including subdirectories).
Could anyone point out how to edit the run configuration to achieve this? I already managed to run single tests but the configuration for them were more complicated than to just run them from command line.
Software used:
OS: Mac OS 10.7 Lion, PHPStorm 6, Yii 1.1.13 and PHPUnit 3.7.
You can set your PHPUnit configuration and bootstrap file in the project settings (PHP -> PHPUnit). Now whenever your run a single test, testcase, directory etc. PHPStorm will use your bootstrap.
If you are using Yii, your test classes probably extend from CDbTestCase or CTestCase. PHPStorm does not know that these are tests cases, therefore it doesn't run them with PHPUnit automatically as it should with other tests cases.
What you need to do is setup Yii Framework in your PHP Include Path. You can access this menu by going to External Libraries in the left column of PHPStorm where you see your files. Once you add Yii to your projects PHP Include Path you will see the test files icon changes and has a red and green play like icon.
This means that you will be able to run them and PHPStorm will use your PHPUnit configuration to do so.
For more detailed information on how to configure phpunit with phpstorm check this article:
http://trickortip.com/825/programming/php/phpunit-vagrant-vm-remote-php-interpreter-phpstorm-mac.html/