In Intellij, right click on a test does not present a "Run" option - intellij-idea

In IntelliJ when I right click on a test I dont see a "Run ClassX or MethodY" anymore. In fact there is no "run" window and when I right click I cannot run any class.
It was all working fine about 3 hours ago so I am not quite sure what has changed.
IntelliJ 10.5.1 (Licensed and NOT community edition)
Java 1.6.0_24
This happens for all projects.
Update 1
I installed IDEA 11 and imported settings from 10 and then saw that it was not a free upgrade close IDEA 11 and started using IDEA 10. I am fairly certain things stopped working from that point but not sure. Is that a problem? Can I somehow delete IntelliJ configuration directory somehow and restart?
Adding a screenshot when I don't get Run option on right click:

My problem was that my test class wasn't public. I needed:
public class MyTest {
#Test
public void testMethod() {
instead of:
class MyTest {
#Test
void testMethod() {

If your project is a maven project then you can just right-click on the pom.xml file and select "add as Maven project".
This approach worked for me. (green plus third from the bottom)

I had the same problem. To fix it, I had to ensure that my class had a proper main method:
public static void main(String[] args) {
}
Every keyword in the above statement is critical. If you omit one, IntelliJ wont' recognize it. Easy-to-forget keywords are static, void, and the String[] args argument.
I had forgotten the arguments in mine ;-)
Also make sure your source code is inside a src folder which is marked as such by IntelliJ.

In my case, the cause was disabled JUnit plugin. (File — Settings — Plugins — JUnit, check, OK)

If you're using JUnit 5 (Jupiter), this happens when you use the old #Test annotation from JUnit 4. Just replace
import org.junit.Test;
with
import org.junit.jupiter.api.Test;
and IntelliJ should show the "Run" button again.

Ok after tremendous amount of eyeballing I located a {HOME}/.java directory which seemed to contain some Jetbrains related preferences. I deleted that directory plus {HOME}/.IntelliJ* directories. Then deleted all my intellij installations and downloaded it again from scratch and it now works fine..
Sigh....

Disabling gradle plugin solved the issue for me (community edition 2018.2)

In my case i right clicked the src folder and went to -> mark directory as -> sources root.

I had the same problem. I solve it by
File -> Invalidate Caches / Restart
right click on the top pom.xml -> Maven -> reimport

There should be no need to delete any configuration files.
I found that I used to have the Run option in the context menu to select either run tests or run Scala tests, etc. After I had selected an option for the first time, my options were no longer there.
I was able to resolve this issue and select the type of tests I wanted for that folder by creating a Run/Debug configuration following the instructions found in the documentation here...
https://www.jetbrains.com/help/idea/2016.1/creating-run-debug-configuration-for-tests.html?origin=old_help

As i had the same issue , i could clearly See that #Test is not providing any hint when i press control key and hover , and the same was confirmed as External Libraries was not having Gradle Dependencies added so i had to update the project as gradle project suggested by a pop up when you start Intellij.

I could resolve the issue by disabling the Gradle plugin from the Plugin menu and restart.

If the project is already added as a Maven one, unlink it.
right click on the project -> Maven -> Unlink Maven Projects
Then link it again:
right click on pom.xml -> + Add as Maven Project

I've just had the same problem and solved it in the following way.
Go to your $USER/$INTELLIJ directory e.g. $USER/.IdeaC2018.3 then find config/plugins. Rename the plugins directory and restart IntelliJ.
My guess is that the problem was caused when I upgraded IntelliJ and incompatibilities with the cucumber plugin.

For me this happened after updating Idea, and then updating all Plugins. Apparently Idea had not restarted yet. Going to File -> Settings -> Plugins and clicking 'Restart Idea' solved the problem

if you can see the play button in left side of the main function then click right click and press run.

in my case, I did not have an output folder.
file -> project structure -> under 'project' tab there's 'Project compiler output' -> define your folder.

Unfortunately, none of these worked for me. I had to
'File' -> "Invalidate Caches / Restart"
Click on pom.xml file, and then 'maven' -> "Generate Sources"

Search for pom.xml file --> Right Click on pom.xml --> Click on Add as Maven Project.
You should get a pop-up, saying downloading Mavin Plugin.
Wait till it gets completed. It takes some time depending on the number of content in pom.xml.
In the below screenshot, "BackendApp.java" is Driver Java file that contains
public static void main(String[] args){}
Right Click on such driver java file and you see Run option in green color.

I had this problem with a Kotlin project. Following action solved it:
right click on test folder -> select Mark Directory as -> choose Test Sources Root

So I had this problem on pycharm and the problem was that there was already a run configuration (in the dropdown next to the play button) that had the name of the file. When i deleted that run configuration it would create a new one that was correct.

I had the same problem and I tried all the above solutions nothing worked for me but after I install TestNG plugin it's started working since there are some TestNG annotations used in my unit tests

I had the same problem on my Intellij 2019.3 after that I updated from 2019.2.4. I thought that the problem came from the updated first, but the rollback didn't fix, so I tried de solution above e the problem was fixed. After configuring all my projects from scratch the problem get back, so I started to check everything I did. I discovered that an old project from Eclipse that uses files .launch to run and need some plugins to be able to execute on Intellij was causing the problem, after disable the following plugins the test option return.

In my case, my project is using Bazel.
The solution was to sync Bazel from Bazel plugin.

Since this is a top Google result when trying to figure out how to run a Scala project, and since for some reason IntelliJ (I'm on 2020.1.2) doesn't automatically create a run configuration for a Scala project (in contrary to a Java project), it's worth laying out the basics for future readers:
Click on "Edit Configuration" on the top right of the screen.
Inside the opened window, click the + button its top left.
Choose "Application".
Now, let's go through the required fields:
in the "Name" field, enter a name for this configuration, e.g. "run".
in the "Main Class" field, enter your main class name.
Alternatively, use the ... button to the left: inside the window that opens, click the "Project" tab, navigate to your main class, pick it and click "ok".
Note: If your main class doesn't have a main method, IntelliJ would show an alert. see listing 9 below.
Make sure the value in "Working Directory" field is correct (it should be the project folder).
in "Use classpath of module", select your module (see project vs module in IntelliJ)
That's it for configuring. Click "Apply", and close the window. Here's an example final result:
Note that my Main class is part of a package named Demo, but having a package is not necessary.
Inside the main class, make sure there's a main method.
See #Josiah Yoder answer for java, and for Scala it's:
def main(args: Array[String]): Unit = {
}
That's it. You should now have the green run and debug buttons enabled.

Seems there are version conflicts between plugins and IDEA itself that commonly break this functionality. Many of the solution here indicate people manually trying to identify the plug in, I found that to be impossible. So here is a generic way, without having to uninstall IDEA as one solution proposed:
File > Settings > Plugins > gear icon > disable all downloaded plugins
This fixed it for me.

Make sure the method is not static! JUnit only allows #Test before instance methods but Intellij doesn't complain even if you use #Test above a static method.

Related

IntelliJ 15, SpringBoot devtools livereload not working

Having issues with the new LiveReload feature with Spring Boot devtools 1.3. It doesn't reload on class changes. I've seen it demo'd with IntelliJ # Devoxx 2015. Is there some IDE setting I need to have enabled? I'm running via the IDE and not through Gradle. I tried enabling "Make project automatically" which doesn't seem to help.
It seems to load correctly and is looking in the correct path
2015-11-23 05:55:30.592 DEBUG 4700 --- [ restartedMain] o.s.boot.devtools.restart.Restarter : Starting application com.myapp.Application with URLs [file:/E:/Projects/myapp/build/classes/main/, file:/E:/Projects/myapp/build/resources/main/]
My files
build.gradle
buildscript {
ext {
springBootVersion = '1.3.0.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'war'
war {
baseName = 'myapp'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
configurations {
providedRuntime
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-devtools')
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.projectlombok:lombok')
compile('org.springframework.boot:spring-boot-starter-web')
compile('net.sourceforge.jtds:jtds:1.3.1');
testCompile('org.springframework.boot:spring-boot-starter-test')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-starter-parent:Brixton.M3"
}
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.7'
}
HelloWorldController
#Controller
public class HelloWorldController {
#RequestMapping("/")
#ResponseBody
String home(){
return "Hello World test";
}
}
if you use IntelliJ IDEA, adding the spring-boot-devtools is not enough. This is because unlike Eclipse, you need to explicitly tell IntelliJ IDEA to “Make The Project” for it to build to the target classpath.
see on youtube
The easiest solution: run app debug mode and press Ctrl + f9 (short-cut for build)
or
You need to enable the “Make project automatically” option. You can
find it in Settings – Build, Execution, Deployment – Compiler
To open the registry, Press Ctrl-Alt-Shift-/ and select "Registry" from the menu that appears, enable the “compiler.automake.allow.when.app.running”
check-box.
To solve this You can do like:
Add LiveReload extension in your browser.
Add devtools dependencies to your pom.xml(if it's maven (spring-boot-devtools)).
In your intellij IDEA go to: file->settings->build,execution,deployment. Go to ->compiler->build project automatically.
In your intellij IDEA: SHIFT+Ctrl+A ->registry-> compiler.automake.allow.when.app.running
I am guessing you are coding and expect DevTools to auto-magically figure out you have changed something in your project? Devtools does that by watching your classpath folder(s). When a .class file (or a resource) has changed, devtools take the appopriate action.
If you don't see anything, that's probably because you're just coding and not updating the classpath. You have to invoke Make Project to update the classpath. See the documentation
In IntelliJ 2021.2 compiler.automake.allow.when.app.running option dissappeared. This option was moved to Advanced settings:
LiveReload and restart are different features. Livereload allows you to detect changes in resources/static folder and notify browser that files changed and the page should be reloaded.
Your question describes Restart scenario. If you want your application to reload automatically on *.class-files changes, make sure your IDE outoputs compiled classes to:
build\classes\main
In Intellij go to Project Structure (Ctrl+Alt+Shift+S) and setup project compiler output dir. After this you can make changes in your classes and press Ctrl+Shift+F9 to recompile current class or hit Ctrl+F9 to recompile the whole project. Spring Boot Devtools will detect changes in build\classes\main and perform restart of your application automatically.
If you want to enable LiveReload for your static assets add the following (otherwise you won't see cahnges of static content while executing bootRun goal):
bootRun {
addResources = true
}
Follow below simple steps, you will be up and running in less than 2 minutes.
Press Ctrl+Shift+A
Search for Registry ...
scroll and find "compiler.automake.allow.when.app.running" then select the checkbox to make it active.
Click close
File Menu -> settings ...
Expand Build, Execution, Deployment
Select Compiler
Select checkbox Build project automatically
Apply
Click Ok
Now stop your application server and then start your application, that's it you will find automatic restart/reload activated when any changes are detected in the project.
Happy Coding/Hacking.
Live reload is a different feature than the problem you have asked the solution for.
In your case as you want to reload your classes after changing them, you need to follow the following 3 steps-
Make change in compiler settings
Make changes in the registry
Make changes in the run/debug configuration
That's it!
After modifying your classes, you can simply press ctrl+F10 to reload the modified classes. You are good to go then!
Addtionally, if you want to configure single point of reload upon modification: https://www.logicbig.com/tutorials/spring-framework/spring-boot/trigger-file.html
For Live Reload:
When a Spring Boot application is running in Intellij IDEA, the templates are served from out/production/resources/templates directory. You can change this behavior and serve the templates directly from src/main/resources/templates directory in development mode. Create a file application-dev.yml in src/main/resources directory and paste the following code snippet in it:
spring:
# Templates reloading during development
thymeleaf:
prefix: file:src/main/resources/templates/
cache: false
# Static resources reloading during development
resources:
static-locations: file:src/main/resources/static/
cache-period: 0
To load the above properties, you need to activate and set the default Spring Boot profile to dev. Add the following property to your application.yml file:
spring:
profiles:
active: dev
Start your application. Now whenever you make any changes in your html files, all you need is to refresh the browser to see the changes!
From the documentation here
As DevTools monitors classpath resources, the only way to trigger a restart is to update the classpath. The way in which you cause the classpath to be updated depends on the IDE that you are using. In Eclipse, saving a modified file will cause the classpath to be updated and trigger a restart. In IntelliJ IDEA, building the project (Build → Make Project) will have the same effect.
intellij 2021.2 has moved this option to AdvancedSettings:
Before anything you need to know devtools is reloading pretty much everything under src/main/ path not the changing to pom.xml file.
1- Add Spring Boot devtools dependency to your maven pom.xml file.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<version>your-desired-version</version>
</dependency>
2- Restart the project and reload maven.
3- Add live reload extension for your browser from http://livereload.com/extensions/
4- On IntelliJ idea 2021+ under File->Setting->Build, Execution, Deployment->Compiler: check build project automatically
5- On IntelliJ idea 2021+ under File->Setting->Advance Setting: check allow auto-make to start even if developed application is currently running
6- change something under src/main (it could be java code, template, or anything else) other than method signature, parameters, or something like this. For example, change a simple line of your code or change a String literal or some stylesheet in the template.
4- You can skip lines (3-4-5-6) and rebuild the current file by Ctrt+shift+f9 or rebuild the whole project by Ctrl_f9 or if you did the preceding lines and you don't want to even press Ctrt+shift+f9, you don't need to rebuild just enjoy the result on the browser.
5- Enjoy the result on the browser.
For me,
I update to the latest version and in File -> Setting > Advance setting and check
To answer the above question let us first understand a feature in Intellij Idea. You must have seen that the file that you make change need not be saved. And the change that you make in any non .class file remains saved. To cross verify please make some change to the .java file(you can choose any other file as well) and close it and it won't prompt for Saving it and when you reopen the file then your changes are still there.
But if you check the .class file the changes made are not reflected which is obvious because build has not happened.
On the contrary when we enable automatic build in Eclipse it is done on an event and the event is Saving the File -> Ctrl+S(Windows). But in intellij idea that event is not happening or we do not carry out that event.
So, consider the scenario when we do not have spring-boot-devtool then, in that case, we always had to rebuild or restart the server to pick up the changes thereby causing an event.
Now, regarding spring-boot-devtool as Ankush92 rightly mentioned that devtool monitors the classpath changes and restart happens only if there is any change in the classpath.
But as I explained earlier we are just adding our code changes in the non .class file and expecting devtool to trigger a restart even when that change is not reflected in the class path.
Let me mention this again that in eclipse the event to do the same is Saving the File(Ctrl+S) when automatic build is enabled.
So, now the question is how to have a workaround and mimic what Ctrl+S does in Eclipse into the Intellij Idea. It's quite simple lets build the application and the shortcut for that is Ctrl+F9. This will trigger the same effect in intellij as Ctrl+S(in this scenario) in eclipse and help the devtool to find the change in the classpath thereby encouraging it to restart the server. So everytime you make any change in the file and want the server to restart just press Ctr+F9.
I hope this explanation and the workaround helps.
Edit - Macros - Start Macro Recording
File - Save All
Build - Build Project
Edit - Macros - Stop Macro Recording - You can save the macro name as “Save & Make Project”
Preferences - Keymap - Macros
Go down to expand the macros directory to find your newly macro (i.e. “Save & Make Project”).
Double click to Add Keyboard Shortcut and press Cmd+S if you use Mac and Ctrl+S if you use Windows.
Intellij will prompt saying that Ctrl+S already exist just click 'Replace'.
Now all set and Ctrl+S should trigger Spring-Boot Devtools
Reference: https://tomyjaya.github.io/2016/10/08/spring-boot-dev-tools-in-intellij/
In IntelliJ IDEA 2021.2, compiler.automake.allow.when.app.running option is disappeared.
So follow these steps,
File ⇒ Settings ⇒ Build, Execution, Deployment ⇒ Compiler ⇒ Build project automatically
Advanced Settings ⇒ Allow auto-make to start even if developed application is currently running
Add this line to the application.properties file ⇒ spring.devtools.restart.enabled=true
I am using IntelliJ idea 2021.2.2(ultimate edition).
I followed these steps,
File -> Settings -> Build, Execution, Deployment-> Compiler add tick to Build project automatically checkbox
Next,
Press Ctrl+Shift+A
Search for Registry ...
scroll and find "compiler.automake.allow.when.app.running" then I can't find that.
then I reserch about that I find In IntelliJ 2021.2 compiler.automake.allow.when.app.running option dissappeared. This option was moved to Advanced settings:
Advanced settings
I discovered that IntelliJ wasn't even using my Gradle configuration.
Visiting Build, Execution, Deployment > Build Tools > Gradle then under Delegate Settings I selected Build and Run Using and made it Gradle.
Working like a charm
For reference, here is my build configuration:
plugins {
id 'org.springframework.boot' version '2.1.6.RELEASE'
id 'java'
id 'idea'
}
apply plugin: 'io.spring.dependency-management'
group = 'test'
version = '0.0.1'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
}
This works well instead of:
bootRun {
addResources = true // Did not work for me
}
apply the following steps:
Add LiveReload extension in your browser.
link: https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei
Add devtools dependencies to your pom.xml(for maven) or build.gradle (for gradle)
for maven:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
for gradle
compileOnly("org.springframework.boot:spring-boot-devtools")
file->settings->build,execution,deployment. Go to ->compiler->build project automatically.
Ctrl+Shift+A ->registry-> compiler.automake.allow.when.app.running
Ctrl+Shift+A ->Edit Configurations->Spring Boot->your application ->
I've been facing this problem a lot on last months on my MAC. Even when following these steps listed here like checking "Make Project Automatically" and "Compiler Automake".
However at my Job, where we use Windows, it works perfectly when I do follow these steps.
The solution for this problem on a MAC I found though is to add a new Run Configuration (Press ⌃⌥R, then press 0) then add a new Maven configuration. On the "Command line" input set "spring-boot:run". Press "Apply" and "Ok" and run the project by selecting the new configuration created.
Of course you could just open a new terminal and just type "mvn spring-boot:run" it will work too.
This worked for me. Add the below line in application.properties file,
spring.devtools.restart.enabled=true
If LiveReload worked for you in the past and then suddenly stops working, and if the other proposed solutions don't work, try uninstalling and reinstalling the LiveReload Browser Plugin. That's what finally fixed it for me.
After finishing all the settings above, you should recompile the html file that you want to reload!
Build → Recompile 'yourHtmlFile.html' (Ctrl+Shift+F9 in Windows)
File -> Settings -> Build, Execution, Deployment-> Compiler
add tick to Build project automatically checkbox
Ctrl+ Shift+alt+/ -> Select registry
add tick to compiler.automate.allow.when.app.running
IntelliJ IDEA > preferences > Tools > Advance Settings > Compiler > check the box to allow auto-make to start even if developed application is currently running.
Add the following dependency on the appropriate pom.xml.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
Make the changes that you want to make while the server is running.
Build > Build Project
Reload the browser
If its Maven and you want dev-tools then check if in your pom.xml, the dependency has been imported by Intelli J properly.
In my case it was showing in red so I did a Maven refresh and that resolved my issue after following other suggestions of Registry from other comments.

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 Report Highlighting error when using routes in Controller

I have a Scala Play project. I'm using Play 2.2.1. I downloaded Scala, Play 2 supported and SBT plugins. Everything is OK, but When I call route on Action in the Controller appear following error(Look screenshots):
I'm using IntelliJ IDEA 12.1.6 Ultimate version. Scala version 2.10.2
Anybody know how to fix this problem?
Thanks in advance!
Edit
When I generate my project to Intellij IDEA via "play idea" command in play console, and I opened project in IDEA project structure was such:
Then I saw answer #millhouse and discussing on this githup([Play 2.2] "play idea" creates not working source mapping in target) and I removed following folders from Sources Folders:
target\scala-2.10\src_managed\main\controllers
target\scala-2.10\src_managed\main\views
and "Report highlighting error" disappeared, but now there is another error:
and
my route:
And I've changed "Sources Folders" as shown below:
But it doesn't help me. And remains "Unspecified value parametrs" error.
millhouse's answer helped me find the right answer. Play 2.2 (and perhaps earlier versions, haven't checked) output a scala version of the routes file to project_dir/target/scala-2.10/src_managed/main So for IntelliJ to get the highlighting right you need to make sure that src_managed/main is added as a source folder. The reverse routes for javascript are for some reason included in project_dir/target/scala-2.10/classes_managed so you'll have to add that as well. (In your screenshot it looks like classes_managed is set to excluded so you'll want to un-exclude it by pressing the x button on the right hand side.)
Here's a screen shot of my project structure:
Update:
In Play 2.3 (or perhaps recent versions of IntelliJ) adding the classes_managed no longer fixes the problem. Instead of adding classes_managed to the project's sources add it to it's dependencies. By doing that IntelliJ should be able to pick up the compiled routes.class.
This is a common problem, it's because IntelliJ needs to be shown where to look for the compiled Scala templates and routes file. Here's how I fixed it on my IntelliJ 12.1 installation:
Go to the Module Settings for your project in IntelliJ (select the top-level, hit F4)
Choose the Modules item in the Project Structure window that appears
Select the projectname item (as opposed to the projectname-build item)
Add the compiler's output directory to the Source Folders items;
For Scala 2.10 it's target/scala-2.10/classes
I personally find the IntelliJ UI for this to be very non-intuitive; you might need to take the target directory and/or one of its subdirectories out of the Excluded Folders first
After applying that change, IntelliJ should see the results of compiling each routes and .scala.html file as just-another source file, so they won't show as "broken" and auto-complete should work for them.

IntelliJ with cucumber (java) and step definition location

Ok, so I'm working on a project using IntelliJ and trying to take advantage of its cucumber functionality. I've not worked with the java flavour of cucumber, but IntelliJ seems to want the step definition files in a specific location, relative to the feature files.
I found this: how to define step definitions location for cucumber in intelliJ 12 and other sources that pointed me to been able to add the "glue" property of my run configurations which tells cuke which package to find the step file. So I am at a point where I can run my tests via IDEA. BUT I need to set this every time I run a new test, as Ctrl+Alt+F10 or right click+run test will not start the test with this flag. Also, the ide support is screwed as IDEA doesn't know where the steps are, it doesn't auto complte or Ctrl+Click navigate to steps.
Is there a way to the the IDEA project to always look for steps in a given package both when running the tests and for its auto complete?
Creating self answer for others who might have this problem. My project did not have the steps marked as test source root, and although I DID do this, it was not until I closed and reopened my project that they were picked up. So a simple restart was my answer.
You can set the glue location globally by opening "Edit Configurations -> Defaults -> Cucumber Java -> Glue" and add the package names.
(IntelliJ 12.1.4)
Go File->Settings--> plugins
Install Cucumber for Java plugin
Then you can manage cucumber plugin as shown below
This should redirect you to step definition when you click your test.
Hope this helps
IntelliJ supports a plugin for Cucumber-Java/Groovy. Installing this plugin will enable the navigation from Steps mentioned in the feature file to the Step Definitions.
And after creating the Step Definition, navigation is easily possible
I go in EditConfiguration, Glue section and i put the path from the package above and the package where is your class for steps, ex:
CucumberFramework.stepsDefinitions
It is really nonsense :) but in in my case when IDEA refused to add steps definition automatically due to some plugins installed, e.g. Cucumber for Scala and suggested deleting them that i cant since i need them in other project. So, long story short, to add (Create step definition) you need to create Class in 'glue' dir and some fake Cucumber implementation, build one more time and it resolved my issue.
Background:
When I use IDEA 2018.2
And Java 8
And Cucumber info.cukes:cucumber-java:1.2.4
#When("^I created a Class and put there fake step implementation$")
#And("^I run gradle build one more time :)$")
#Then("^This Class will be able for me from the feature file by ALT+ENTER as usual$")
#And("^It resolved my issue when I was not able to automatically generate step definition$")

How to open and edit multiple projects in the same window?

I build in maven multiple projects (let's name them A,B,C). Project A uses .jar of project B which uses .jar of project C.
I am modifying the code of all A/B/C projects, (A is MVC app, B are business services and C is some shared layer).
The thing is, in Eclipse/NetBeans I can see all of them at once and it's comfortable to modify them. In IDEA though, I have to open 3 instances (or n instances) of IntelliJ IDEA.
Am I missing something? Is there better approach when using IntelliJ? This is the biggest downside of IntelliJ for me atm.
I think this has improved with recent versions of IntelliJ. In my current version (12.0.2), you can add any number of separate Maven projects to the same "workspace".
The simplest way I've found to do this is to click the little + icon in the "Maven Projects" window (View > Tool Windows > Maven Projects) and then select the additional pom file you want to import.
Step 1: open "Maven Projects"
Step 2: select the project you want to import:
Prequisite
Having all the related projects in the same root directory
can be helpful.
Steps
1) First you create a new Empty project
2) Then you select the root directory of all your projects.
This will create a empty project, with a .idea directory that will simply remember the module organisation we are about to do in the next step
3) Then, in the next window, you import the different projects as modules
4) In the next window, to import each project, simply double click on the build.gradle, or pom.xml
The project will be imported as a new module.
5) Done, you now have all your projects as modules, opened on the same IntelliJ project
Yes, your intuition was good. You shouldn't use three instances of intellij. You can open one Project and add other 'parts' of application as Modules. Add them via project browser, default hotkey is alt+1
In IntelliJ 14.1.2, I did it like following:
Select File->Project Structure->Modules.
Select + and Import Module and select the directory of your project(or directory where pom exists) and click OK.
Follow through the next flow of screens and after you click Finish, you should see the project alongside your existing one.
None of the solutions worked for me, since I am not working on Maven projects. There is a simpler solution. Go to:
File->Project Structure->Modules.
Instead of adding module, simply click the third option (copy). Browse your local directory and select the project you would like to add. Module name will resolve automatically. That's it.
Update: When you want to reopen to project with multiple sub-projects, in order to avoid re-doing steps as described above, just go to
File->Open Recent->'Your Big Project'.
Since macOS Big Sur and IntelliJ IDEA 2020.3.2 you can use "open projects in tabs on macOS Big Sur" feature. To use it, you have to enable this feature in your system settings:
System Preferences -> General -> Prefer tabs [always] when opening documents
After this step, when you will try to open second project in IntelliJ, choose New Window (yes, New Window, not This Window).
It should result with opening new project in same window, but in the new card:
To expand #Neo answer:
after choosing your directory. select import module from external model and choose your model (maven in this case).
Then check keep project files option from next dialog. It will keep all files in original directory.
Your final project structure would be something like this.
Now you can add your module as dependency to other module's pom.xml and if you change the source code of your dependencies, Intellij takes care of updating your project (there is no need to run mvn build manually for dependencies)
new empty project
File -> New -> Module from Existing Sources
For who uses Gradle can also avail the same:
Go to:
1. View --> Tool Windows --> Gradle
2. Click on the + button and add your build.gradle file
Open preference -> appearance & behaviour -> System settings -> select (open project in new window) then apply.
Then you could open and edit multiple projects.
You can use Armory plugin which makes switching between projects comfortable. The default shortcut for Project List is Alt + A.
By default currently opened projects are displayed at the top of this list (with bold style).
Use the button for the add maven projects and go inside the folder of the project. Then, select the pom.xml file and add them in the IntelliJ.
Press "F4" on windows which will open up "Project Structure" and then click "+" icon or "Alt + Insert" to select a new project to be imported; then click OK button...
To Intellij IDEA 2019.2, F4 + click on module, click to + for add any project from your HDD, above this menu yo can edit the IDE with you create the project and more options, very easy
For people not using maven to build and wanting to add a new project (I am using intellij 14.1.3):
Right click the top level folder in the project view, select new ->
Module
Name the module the same name as the project to be added
From the top menu select File->New->Project. Enter the same name as
the new module, same folder locations as well.
Open the Project, and wait for intellij to create the project
structure.
Close this new project, and open the original project the module was
added to in step 2
Depending on your builder, additional steps will be needed to add it to the build process.
For SBT, and in the top level project I modified the Build.scala file to aggregate the new project, and added the project in the SBT projects window. More info on SBT multiproject builds: http://www.scala-sbt.org/0.12.2/docs/Getting-Started/Multi-Project.html
"IntelliJ IDEA 2022.1.1 (Community Edition)" you have to navigate
To Add Exiting Module to same window navigate "File -> New -> Module from Existing Sources" then it will allow you to select pom.xml and then click "Create" button next window then project will be added to your current workspace.
Note :: Who ever switches from Eclipse to Intellij this is the first problem
Assuming they are under the same folder, click File-Open File or Project-<parent folder>.
you can use import module option which will open it just like eclipse in the same navigator.
For IntelliJ Idea 2021.3.3 users, The below solution didn't work for me, although I was selecting my project main folder, I've gotten only the main and test folders imported!
Peoject Structure => Modules => Import module
The solution is:
view => tool Windows => Maven => click the + icon => add the project POM.xml file
I am new to maven and did not understand how I could work with local maven project added through Viktor Nordling's answer and still have a proper dependency in pom.xml file. The answer is simple: intellij first looks at your locally added module and if it doesn't find one it goes to get the project remotely. You can check this by looking at "external libraries" under your project browser when you add or remove maven module.
Hope this helps anyone.
As of release 2019.2, this is as easy as File->Attach Project.
🎉🎉🎉🎉🎉
See: https://youtrack.jetbrains.com/issue/WEB-7968
After importing project into IntelliJ, Go to pom.xml of each module -> right click -> Click on Add as Moven Project. It will add the module as Moven project, do this for all the modules in the Project. Refer this