I have a very simple Java + Gradle project. It builds fine. It runs fine from the shell with \"gradle run\". However, if I try to run inside of IntelliJ, I get:
If none of the above method worked then try this it worked for me.
Go to File > Project Structure> Project and then in Project Compiler Output click on the three dots and provide the path of your project name(name of the file) and then click on Apply and than on Ok.
It should be like that as in the picture i an posting.
Open .iml file. Look for keyword 'NewModuleRootManager'. Check if attribute 'inherit-compiler-output' is set to true or not. If not set to true.
Like this :
component name="NewModuleRootManager" inherit-compiler-output="true">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/app" isTestSource="false" />
After this
Two things to do:
Project Settings > Project compiler output > Set it as "Project path(You actual project's path)”+”\out”.
Project Settings > Module > Path > Choose "Inherit project compile path""
If button ran is not active
You must reload IDEA
None of the suggestions worked for me until I ran the command "gradle cleanIdeaModule ideaModule" info here: https://docs.gradle.org/current/userguide/idea_plugin.html
You have to define a path in the "Project compiler output" field in
File
>Project Structure...
>Project
>Project compiler output
This path will be used to store all project compilation results.
While configuring idea plugin in gradle, you should define output directories as follows.
idea{
module{
inheritOutputDirs = false
outputDir = compileJava.destinationDir
testOutputDir = compileTestJava.destinationDir
}
}