IntelliJ 15, SpringBoot devtools livereload not working - intellij-idea

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.

Related

Intellij maven not exist

Maven on the intellij was unavailable(think removed).I can not make new maven project or import dependency form pom.xml using: right click->maven->reImport.No maven option exist when right click.
Maybe Maven integration is disabled.
Windows: Navigate File > Settings > Plugins
MacOS: Navigate Preferences > Plugins
Then switch to Installed tab, search for maven and click enable button.
https://www.jetbrains.com/help/idea/managing-plugins.html
It looks like the installation iscorrupted.
Remove the .IntellijXX or .IdeaICXX settings folder, which can be found under in the current user directory and after restarting Intellij, it should recreate everything fixing the problem.
Apart from getting the Maven option on right click on a project, there is a Maven option on the right hand side of intellij (As shown below, and highlighted). Click on the circle arrows icon for re-importing maven dependencies.
Usually if you open settings and search for the term "maven" you should be able to see under "Build, execution deployment" - "Maven" with its corresponding settings. The Maven Home directory should point to a valid maven installation. For example:
(unix
$ /home/xy/intellij/plugins/maven/lib/maven3
If that doesnt work, try to reinstall intellij by either through intellij (windows software remove) or removing the config files in your home directory
(unix)
$ /home/xy/.intellijXY
(windows)
%USERPROFILE%\.IdeaICXX
In the file menu select settings -> plugins.
search for maven, select maven, select enable. Restart intellij.
Once restarted you will now have the option to start new maven project and maven functionality will be accessible in all your previous projects.
Tried a few solutions but this is the only thing that worked. In short make sure maven is ON for you.
Try navigating to the pom.xml file and open as a project.
Maven is not integrated
Navigate to File > Settings > Plugins
Search for 'maven' here and add it
Click on enable and restart the intellij
You will be able to find 'maven'

IDEA 2016.1, Gradle's processResources expanding not working automatically

I have an IDEA 2016.1 Enterprise and a Gradle 2.12 multi-module project. In one of the modules, in src/main/resources, I have a file which I would like Gradle to 'expand', here is my configuration:
processResources {
filesMatching('my.properties') {
expand(project.properties)
}
}
(I would like to expand just this single file, and just copy the rest.)
It all works fine when built on the command line, but not by default in IDEA - when I clean and build the project, the file lands in build/resources/main but the placeholders are not replaced. I have to manually invoke the Gradle processResources task using the Gradle pane in IDEA and double clicking on the task.
Is this something I should report to Jetbrains (i.e. a bug) or has anybody have it working and I should change something in my configuration?
When you build from command line, you are using gradle. However, when you build the project from intellij, by default intellij doesn't use gradle to build, but use its internal build system which doesn't understand your gradle's processResources.
One way to solve it is to check "Delegate IDE build/run actions to gradle" as shown below:
If you don't want to use gradle build in intellij, there's another workaround - add processResources as a gradle task to run after build in your "Run/Debug Configurations":
Try adding the dependency in your build.gradle file, eg.
assemble.dependsOn processResources
This should work if you have java plugin applied.

How to get IntelliJ to associate Gradle sources with build.gradle?

When writing Gradle scripts for my Java project, specifically, when writing build.gradle files, IntelliJ does not recognize the Gradle API.
For instance, Gradle methods calls like apply, dependencies configure appear with a black line under them and it is not possible to navigate to method declarations, there is no auto-completion etc.
I managed to work around this by adding compile gradleApi() to the build's dependencies block. However, I don't want to have this explicit dependency in my code.
I tried editing IntelliJ's project structure and add a dependency on a Gradle library (tried gradle-core and gradle-all) to my modules, but that seems to have no effect.
Is there a way to make IntelliJ associate all build.gradle files with the Gadle sources?
I solved this problem as follows:
As mention in already posted answers, configure gradle
update gradle/wrapper/gradle-wrapper.properties file
change bin to all in distributionUrl i.e.
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
to
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip
OR
[optional] If you are using old version of gradle wrapper and wanted to upgrade, then execute
./gradlew wrapper --gradle-version 6.8.3 --distribution-type all
Update gradle task (if present in build file)
wrapper {
gradleVersion = '6.8.3'
distributionType = Wrapper.DistributionType.ALL
}
Before importing the project to IntelliJ-Idea IDE, update build.gradle and add java and idea plugin to the plugins list
plugins {
id "java-library"
id "idea"
}
From a terminal, execute ./gradlew clean build idea or simply ./gradlew idea
Import project to IntelliJ idea.
Go to Preferences --> build,Execution,Deployment --> BuildTools --> Gradle
You can see
Restart IntelliJ idea IDE.
So above we have configured both of the options so choose either of them, except the specified location option. That's it.
Before
After
Autocomplete functionality as mentioned in this answer.
I had similar frustrations with Grails 3, which defines and runs a wrapper task when an app is created. Changing to the "all" zip in the wrapper properties file did not work because this kept getting changed back to the "bin" zip.
This was solved when it was understood that the "gradle-wrapper.properties" file simply stores the values from the "wrapper" task, and if this task is run after the properties are changed, they get changed right back.
This is easily fixed by setting some properties on the wrapper task:
wrapper.gradleVersion='3.2.1'
wrapper.distributionType=Wrapper.DistributionType.ALL
Now importing the project into IDEA gives you smart editing of your build.gradle.
when I choose build.gradle in IDEA and open it, IDE prompts
You can configure Gradle wrapper to use distribution with sources. It will provide IDE with Gradle API/DSL documentation.
I choose Ok, apply suggestion!
after project refreshing I am able to use code completion
before you import your project, configure it to use the customizable gradle wrapper as per the instructions here :-
https://docs.gradle.org/current/userguide/gradle_wrapper.html
add a task to your top level project like this:-
task wrapper(type: Wrapper) {
println "Wrapper gradleVersion = '2.12'"
gradleVersion = '2.12'
}
or whatever the latest version is.
make sure you can build the project from the gradle command line before you try importing into intelliJ, using the ./gradlew command, which will download and install a gradle distribution for you the first time you build.
set your java home, intelliJ home and gradle home variables in your machine and in intelliJ (mine look like this, yours may be different depending on your setup and your history of hacking around your machine...:-
(from .bashrc
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
)
When you do import, choose the customisable gradle wrapper. if all is well, when you open the top level build.gradle for your project, you will be asked to configure sources for the gradle dsl, which will also update your gradle wrapper properties file to this:-
#Thu Mar 31 14:04:00 BST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-all.zip
.. the change being from ... bin.zip to all.zip. and that's it. This had been giving me lots of grief for a long time, but that's the way to do it. (on IntelliJ IDEA 2016.1 CE at least...)
most of this was in
Dimitry's answer too, but I couldn't get it to work using the default wrapper , it had to be the customisable wrapper.

Unable to make the module: related gradle configuration was not found. Please, re-import the Gradle project and try again

I use IntelliJ IDEA Ultimate 14 and Gradle 1.2. I manage the project from the console, but I need to debug some of the code from the IDE.
When I try to make the project, this error window appears. When I try to debug the project,
Error: Unable to make the module: idappcli, related Gradle configuration was not found.
Please, re-import the Gradle project and try again.
is written in the message window. How can I add the regular output paths to the project?
Try by opening the gradle task view and then click the refresh button. For me it solved the problem.
I also had a similar problem,
Go to : View -> Tool Windows -> Gradle.
Then press in Refresh Icon
This fixed the issue "Please, re-import the Gradle project and try again." for me (IntelliJ Ultimate 17.3.3):
(1) Detached Gradle project:
(2) Closed the project and (3) re-opened it via File > Open recent. IntelliJ will promt to import the now unlinked Gradle project. (4) Imported it and selected "Use auto-import" in the dialog.
I had the same problem with my Intellij IDEA version 2016.2 (Mac)
The solution was: In Intellij, Click on "View" then "Tool Windows" then "Gradle" then click on
I had to make sure the Use auto-import and the Use default gradle wrapper (recommended) were both checked.
File > Other Settings > Default Settings > Build, Execution, Deployment > Build Tools > Gradle
I faced the similar issue when i update my IntelliJ Idea.
To fix it i ran the below command in terminal and it fixed my problem.
gradle cleanIdea idea
For most people the refresh of Gradle that has already been suggested might solve the issue.
For the others I figured out, that deleting the .idea direcotory and reimporting the project might help.
It can be that your resources directory is not added to classpath when creating a project via Spring Initializr. So your application is never loading the application.properties file that you have configured.
To make a quick test if this is the case, add the following to your application.properties file:
server.port=8081
Now when running your application you should see in the spring boot console output something like this:
INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port(s): **8081** (http) with context path ''
If your port is still default 8080 and not changed to 8081, your application.properties files is obviously not loading.
You can also check if your application runs with gradle bootRun from command line. Which most likely will be work.
Solution:
Close IntelliJ, then inside your project folder delete the ".idea" folder
Reimport your project to IntelliJ like following: "Import Project" -> "select ONLY your build.gradle file to import". (IntelliJ will automatically grab the rest)
build and run your application again
See official answer by IntelliJ Support:
IDEA-221673
This works for me:
Close the IntelliJ Idea
Delete 'gradle' and '.gradle' folders from the project root
Start IntelliJ Idea and import the project as gradle
In my case the root cause was a missing proxy configuration. Once I configured it properly I was able to Refresh gradle projects and it finally downloaded missing files and set up the project correctly.
File > Settings > Appearance & Behaviour > System Settings > HTTP proxy
then
View > Tool Windows > Gradle
and Synchronize button
I went into the IntelliJ Gradle preferences:
Menu: Preferences > Build, Execution, Deployment > Build Tools > Gradle
And under Project Level Settings, switched the radio button to "Use default gradle wrapper (recommended)"
Hit the make button, and was in business!
#user1339 I also had the same problem. Please, read this question Building war with Gradle, Debugging with IntelliJ IDEA. It'll be very helpful for you. And recommendation for the 'Make' task. As message said, I should try to re-import the Gradle project and try again. In my case this advice became very helpful.
I recommend to try to 'Build > Rebuild Project'.

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

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.