156

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:

Cannot start compilation: the output path is not specified for module "xyz" Specify the output path in Configure Project.

My "Compiler output" is set to "Inherit project compile output path". I don't want a custom output path, whatever that is, just do a normal gradle build and run.

2
  • 2
    When running code from IntelliJ, it will be compiled and run by IntelliJ rather than Gradle, and a different build output directory will be used. (Android is a different story.) However, if the Gradle build is imported correctly, the IntelliJ output directory should already be configured. Commented May 19, 2014 at 6:16
  • 1
    On the answers below, be careful to give a path in which you have user permission to write, or else it won't work. Commented Mar 28, 2023 at 13:39

19 Answers 19

143

You have to define a path in the "Project compiler output" field in

File > Project Structure... > Project > Project compiler output

Image

This path will be used to store all project compilation results.

Sign up to request clarification or add additional context in comments.

Comments

132

You just have to go to your Module settings > Project and specify a "Project compiler output" and make your modules inherit from project. (For that go to Modules > Paths > Inherit project.

This did the trick for me.

4 Comments

Well, not choosing the Inherit Project option worked for me
Why can it not figure this out for itself. Everyone says IntelliJ is better than Eclipse but in my experience, it can't think for itself.
FYI, I've found that in IntelliJ you do a File > New > Module... and create a Java module, the output path should get set by default.
If this doesn't appear to work, don't forget to restart IntelliJ. Fixed it for me.
26

I'm answering this so that I can find the solution when I have to google this error again.

Set project compile output path to path_of_the_project_folder/out. That's what is working today. The intellj documentation makes it seem like we can select any folder but that's not the case.

1 Comment

This was what I needed to do! Thank you!
13

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.

2 Comments

There is no picture in your answer.
@priyanshu : Seriously, there is no picture, in your post.
12

While configuring idea plugin in gradle, you should define output directories as follows.

idea{
    module{
        inheritOutputDirs = false
        outputDir = compileJava.destinationDir
        testOutputDir = compileTestJava.destinationDir
    }
}

2 Comments

looks great. What file do I put this configuration in?
You should put it to build.gradle file in your project.
6

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" />

Comments

6

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

Comments

4

Two things to do:

  1. Project Settings > Project compiler output > Set it as "Project path(You actual project's path)”+”\out”.

  2. Project Settings > Module > Path > Choose "Inherit project compile path"

Comments

1

I get this error too when creating a project in IntelliJ without using a template.

I have 2 SDKs installed: Amazon Corretto and java version 11.0.4 and so, what I do when I have this error is "change the SDK" it usually works fine with Corretto

to do that you need to click on File (in IntelliJ)/ Project Structure / Project / Project SDK: select corretto from the dropdown list (or check the option in your computer) as shown here

hope this will work for you too

Best, Constantin

Comments

1

Bugs caused by missing predefined folder for store compiled class file which is normally is /out folder by default. You can give a try to close Intellij > Import Project > From existing source. This will solve this problem.

1 Comment

This is what finally fixed my issue
1

Change the Path of the Compile Output Path inside File > Project Structure > Modules > Paths

  • Check the Use module compile output path
  • Inside Output Path, set the output path as /target/classes. e.g. - S:\myProjectFolder\myProject\target\classes

This worked for me. Don't forget to clean install your project once. If it doesn't work, make sure you restart Intellij once.

Comments

1

In my case, issue was with first time set up & intellije did compile with default java version, which I later changed, but class path error wasn't resolve. To resolve this I had to delete .idea folder, restart IntelliJ & set up project again. This resolved my issue.

Comments

0

If you are seeing this for a module that you have added using Gradle's new test suites feature, it can be because the module settings show screen it is not using inheritOutputDirs. Although you can fix the issue by changing the setting there, you are correctly warned that it will revert next time the gradle sync runs.

Instead you can force all modules to use inherit with:

idea {
  module {
    inheritOutputDirs true
  }
}

Comments

0

I've come across this problem, when i was deleting maven modules in my project. The case was that whenever when I reimported maven project, the Project File > Modules > Compiler Output Settings was set to "Use module complite output path", but build would start only on "Inherit project compile output path" enter image description here

I tried to google paths to put into there and I found out the paths should lead to target file generated by maven after mvn install - which was missing. After research I have understood that my master pom.xml doesnt have one key property.

<packaging>jar</packaging>

as such:

<project...>

    <groupId>example.project</groupId>
    <artifactId>example-project</artifactId>
    <version>1.0.0</version>
    <name>example-project</name>
    <packaging>jar</packaging>
.
.
.
</project>

Then as shown on the picture I changed paths to target classes and test-classes and everything started to work.

Hope this helps!

Comments

0

In my case changing the "inherit-compiler-output" value in the .iml file 'NewModuleRootManager' tag to false: (After changing the main module to multi-module project settings i broke it, and this solved it for me)

    <?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
  <component name="NewModuleRootManager" inherit-compiler-output="false">
    <exclude-output />
    <content url="file://$MODULE_DIR$">
      <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
  </component>
</module>

Comments

-1

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

Comments

-1

change drop down to start file your project

enter image description here

Comments

-1

Delete .idea folder -> restart IntelliJ --> set the project again.

2 Comments

Only causes more problem.
I have deleted the file and the prjoect has gone.
-1

I was able to fix it very easily by just checking out the project again and starting over from there :D I couldn't make it work with the above approaches and just trying took way longer than just checking out the project a second time!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.