Java “无法开始编译:未为模块指定输出路径...”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23688702/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Cannot start compilation: the output path is not specified for module..."
提问by clay
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:
我有一个非常简单的 Java + Gradle 项目。它构建得很好。它通过“gradle run”从外壳运行良好。但是,如果我尝试在 IntelliJ 内部运行,则会得到:
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.
我的“编译器输出”设置为“继承项目编译输出路径”。我不想要自定义输出路径,无论是什么,只需进行正常的 gradle 构建和运行即可。
采纳答案by KingRao
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
.
您只需转到您的Module settings > Project
并指定“项目编译器输出”并使您的模块从项目继承。(为此,请转到Modules > Paths > Inherit project
.
This did the trick for me.
这对我有用。
回答by lemiorhan
While configuring idea plugin in gradle, you should define output directories as follows.
在gradle中配置idea插件时,你应该定义输出目录如下。
idea{
module{
inheritOutputDirs = false
outputDir = compileJava.destinationDir
testOutputDir = compileTestJava.destinationDir
}
}
回答by mdev
Open .iml file. Look for keyword 'NewModuleRootManager'. Check if attribute 'inherit-compiler-output' is set to true or not. If not set to true.
打开 .iml 文件。查找关键字“NewModuleRootManager”。检查属性 'inherit-compiler-output' 是否设置为 true。如果没有设置为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" />
回答by Mujahed
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
在我在这里运行命令“gradle cleanIdeaModule ideaModule”信息之前,没有任何建议对我有用:https://docs.gradle.org/current/userguide/idea_plugin.html
回答by BullyWiiPlaza
回答by Kanj
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.
将项目编译输出路径设置为path_of_the_project_folder/out
. 这就是今天的工作。intellj 文档使我们似乎可以选择任何文件夹,但事实并非如此。
回答by priyanshu kumar
If none of the above method worked then try this it worked for me.
如果上述方法均无效,请尝试此方法对我有用。
Go to File > Project Structure> Projectand then in Project Compiler Outputclick on the three dots and provide the path of your project name(name of the file) and then click on Applyand than on Ok.
转到文件>项目结构>项目,然后在项目编译器输出上的三个点点击提供您的项目名称(文件名)的路径,然后点击应用,比上确定。
It should be like that as in the picture i an posting.
它应该像我发帖中的图片那样。
回答by Ali Wu
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"
回答by Constantin
I get this error too when creating a project in IntelliJ without using a template.
在不使用模板的情况下在 IntelliJ 中创建项目时,我也收到此错误。
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
我安装了 2 个 SDK:Amazon Corretto 和 java 版本 11.0.4 等等,当我遇到此错误时我会“更改 SDK”,它通常与 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
要做到这一点,你需要点击文件(的IntelliJ)/项目结构/项目/工程SDK:从下拉列表中选择corretto(或检查您的计算机的选项),如在这里
hope this will work for you too
希望这对你也有用
Best, Constantin
最好的,康斯坦丁