IntelliJ run Scalatest using $MODULE_WORKING_DIR$? - intellij-idea

I have a multi-project SBT config that I've imported into IntelliJ (2019.3). I want each project (module) to run Scalatests from its own directory instead of the multi-project root directory. I went to Run -> Edit Configurations -> Templates -> ScalaTest and set Working directory to $MODULE_WORKING_DIR$, but I get the following error:
"Cannot start process, the working directory '$MODULE_WORKING_DIR$' does not exist".
I am able to use the $MODULE_WORKING_DIR$ macro in my normal run configurations, but it doesn't work in ScalaTest. Is there something I'm doing wrong, or is there a different way to accomplish what I'm trying to do?

Related

SBT can't read environment variables in IntelliJ

I defined a new environment variable in ~/.zshrc like that: export JVM_XMX=-Xmx2048M. I can verify that it was set correctly running export command and finding it in the list.
Now I want to use it in SBT. I've tried these two approaches:
sys.env("JVM_XMX")
sys.env.get("JVM_XMX")
But the value couldn't be found or the Option is None. Errors that I see are:
NoSuchElementException: key not found: JVM_XMX
NoSuchElementException: None.get
What I also tried was to add the variable into SBT in IntelliJ Settings. I went to Build, Execution, Deployment -> Build Tools -> sbt and set VM parameters to -DJVM_XMX=-Xmx2048M. It didn't help.
Anyone knows how to setup SBT to work with IntelliJ correctly?
Versions used:
sbt 1.2.8
IntelliJ IDEA 2019.2.1
As a workaround I was able to use system properties (scala.sys.SystemProperties). This works because this is the way how to find values added into SBT in IntelliJ Settings.
Code example from build.sbt:
sys.props.get("JVM_XMX")
UPDATE:
I was finally able to figure out what was the real problem. My .bashrc file was incorrectly set up (I had the variables only in .zshrc). After adding environment variables into correct rc file, the problem was fixed.
If you'd like this property to be part of your project, and not only in your solution, you can add a file names ".sbtopts" at the root of your repository, next to the build.sbt file.
In this file you can configure the JVM options.
For instance you can add there:
-J-Xmx2048M
I couldn't find the sbt documentation supporting my suggestion, but it works for me :)
I was able to work around this issue by going to Preferences -> Build, Execution, Deployment -> Build Tools -> sbt, then enabling sbt shell for builds and project reload.

While making maven project I am getting "could not calculate build plan" plugins error

I am trying to make a new project in maven, but while making the project I am getting "could not calculate build path": plugins error because of this I am not able to work further.
Steps to reproduce:
Launch Eclipse (I am using oxygen) new version
Go to File ->New ->project->select maven as project option
Enter the required filed for POM file
Now, as maven project start building, I am getting the error.
Please find attached screenshot for the reference.
Try the following steps:
Make sure you have connectivity (you can browse) (This kind of error is usually due to connectivity with Internet)
Download Maven and unzip it
Create a JAVA_HOME System Variable
Create an M2_HOME System Variable
Add %JAVA_HOME%\bin;%M2_HOME%\bin; to your PATH variable
Open a command window cmd. Check: mvn -v
If you have a proxy, you will need to configure it
http://maven.apache.org/guides/mini/guide-proxies.html
Make sure you have .m2/repository (erase all the folders and files below)
If you are going to use Eclipse, You will need to create the settings.xml
Maven plugin in Eclipse - Settings.xml file is missing
You can see more detail in
http://maven.apache.org/ref/3.2.5/maven-settings/settings.html

Play Framework 2.4 and IntelliJ Idea

I am trying to open a play 2.4 project in IntelliJ but since things have changed I don't know how to do this.
In previous versions I could just run
activator idea
Or use the activator UI and click on generate intelliJ project, but in 2.4 the idea command doesn't seem to exist
[error] Not a valid command: idea (similar: eval, alias)
[error] Not a valid project ID: idea
[error] Expected ':' (if selecting a configuration)
[error] Not a valid key: idea (similar: clean)
[error] idea
[error] ^
And the UI seems broken, when I click on generate intelliJ project it tries to compile the app and gives this error:
play/Play$
java.lang.NoClassDefFoundError: play/Play$
Use 'last' for the full log.
Failed to load project.
I created the project from scratch using the play java template with:
activator new
I have also tried importing the folder as a project but intelliJ doesn't seem to identify it as a project
I run into the same problem, as I used IDEA to open a project folder, it had an play 2 app in a sub folder, then I import module (play 2 app) to the system.
And it works well.
After that I have changed the module folder name, then when I run the app, it displayed:
Not a valid project ID: "project team"
I re-checked the folder, and found that in the File -> Project Structure option, the name of module is "root", and the "team" is the module for whole project (not the module imported by SBT), so apparently, the module wasn't functional after I changed the module folder name.
So I found and removed all .idea folder, which is IDEA configureation, then re-open/re-import the module, still not work. I thought it's IDEA cache issue, it do have cache for the opened project, so I changed the project folder from team to something else, clean the .idea folders, and re-open/re-import it. It worked.
If the play app is in the project folder as a sub folder, to import the module at File -> Project Structure.
The project name should be "root" when running it in IDEA. So in this case, you should rename "project team" to "root" in the name field.
Solution 1
In my case (IDEA 2018.2), I changed the lazy val variable in build.sbt, it had the name "root" when my project name was "top", changed "root" to "top".
Before:
lazy val root = (project in file(".")).enablePlugins(PlayScala)
After:
lazy val top = (project in file(".")).enablePlugins(PlayScala)
Change project variable
Solution 2
The method proposed by Tom solved my problem partially, because after rebooting the IDEA I returned the project name back, it was necessary to change the variable from "top" to "root" in build.sbt.
Before:
name: = "top"
After:
name := "root"
Intellij IDEA lets you quickly create a Play application without using a command prompt. You don’t need to configure anything outside of the IDE, the SBT build tool takes care of downloading appropriate libraries, resolving dependencies and building the project.
Before you start creating a Play application in IntelliJ IDEA, make sure that the latest Scala Plugin is installed and enabled in IntelliJ IDEA. Even if you don’t develop in Scala, it will help with the template engine and also resolving dependencies.
Basically, install Play Framework, Scala plugins and import project into Intellij as SBT project. Don't use activator to create IDEA project files. More details here.
It seems I had not updated scala/sbt to the latest version in intelliJ
Once I had done this it noticed that it was a valid project, though the docs don't seem to mention you can import it as an SBT project, just how to create it as a new sbt project (which I did not want to do as I wanted to create it via activator)
I also had the project/play-fork-run.sbt file issue
I use Intellij Idea 16.3.3 and this problem appears sometimes. How I fixed it? You just need to open your SBT plugin and under your project get the context menu then you should choose "Ignore SBT project". After a current process is finished you should turn on this option again. This is work for me:)

Intellij IDEA ignoring files run issue

Hello all I am trying to run a programme using Intellij. The programme runs perfectly in Eclipse and Terminal. However using IDEA it seems to ignore 2 files.
java.io.FileNotFoundException: .\data\def\items\ItemValues.txt (The system cannot find the path specified)
There are no errors normally in Intellij. I just get this error upon running it. The file is there I have checked and path is correct. Intellij just seems to be ignoring it.
Check Working directory in Run/Debug Configuration, you need to change it to $MODULE_DIR$ if you have multiple levels of maven modules.

IntelliJ IDEA 11.1.2 does not copy SQL files to the out folder

I am using IntelliJ IDEA 11.1.2 Ultimate with Gradle 1.0 multi module project. One module represents the domain.
The projects output is points to [project-root]\out. But if I run a unit test the output folder of the domain module does not contain any .sql files at all. . This is how I run the JUnit test within IntelliJ IDEA .
If I run the project using Gradle from command line everything works fine.
Settings | Compiler | Resource Patterns, add the pattern for the sql extension.