java IntelliJ 在同一模块中使用时找不到生成的源
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33260148/
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
IntelliJ can't find generated sources when used in same module
提问by Rolf W.
I'm using annotation processors of Google's AutoFactory. I annotated SomeClasswith @AutoFactoryand referenced new SomeClassFactory().create()somewhere else in that same module.
我正在使用Google 的 AutoFactory 的注释处理器。我注释SomeClass与@AutoFactory和引用的new SomeClassFactory().create()是同一个模块在其他地方。
Maven configuration:
Maven配置:
I added the necessary dependency in Maven:
我在 Maven 中添加了必要的依赖项:
<dependency>
<groupId>com.google.auto.factory</groupId>
<artifactId>auto-factory</artifactId>
<version>1.0-beta2</version>
<optional>true</optional>
</dependency>
When running $ mvn clean compileI see that target/generated-sources/annotions/somepackage/SomeClassFactoryis created and the module compiles without errors.
运行时$ mvn clean compile我看到它target/generated-sources/annotions/somepackage/SomeClassFactory被创建并且模块编译没有错误。
IntelliJ configuration:
IntelliJ 配置:
Reimport all maven modulesPreferences->Annotation Processors->Enable annotation processingRebuild Project
Reimport all maven modulesPreferences->Annotation Processors->Enable annotation processingRebuild Project
This should be enough in my version of IDEA (v14.1.4) if my understanding is correct.
v14.1.4如果我的理解是正确的,这在我的 IDEA ( )版本中应该足够了。
I also performed the following steps:
我还执行了以下步骤:
- Verified that
generated-sourcesfolder is added as a source inProject Structure - Verified that Maven preference
Generated sources foldersis set toDetect automatically - Verified that source is actually generated upon Rebuild (deleted
targetfolder first to be sure it's generated by IntelliJ) - Try to disable
Exclude output pathsin Project Structure, as suggested by @tilpner - Invalidate caches and restart
- Delete
.ideafolder and.imlfiles - Experiment with different settings for
Phase to be used for folders updateinPreferences->Maven->Importing
- 验证
generated-sources文件夹已添加为源Project Structure - 已验证 Maven 首选项
Generated sources folders设置为Detect automatically - 验证源实际上是在重建时生成的(
target首先删除文件夹以确保它是由 IntelliJ 生成的) Exclude output paths按照@tilpner 的建议,尝试在项目结构中禁用- 使缓存无效并重新启动
- 删除
.idea文件夹和.iml文件 - 尝试不同的设置
Phase to be used for folders updateinPreferences->Maven->Importing
Problem:
问题:
After performing all these steps, the generated class doesn't show up in the project explorer. In fact, the entire targetdirectory is nowhere to be seen. Compilation fails with cannot find symbol: SomeClassFactoryand new SomeClassFactory().create()is marked in red in the editor, while Maven generates and compiles without any problems.
执行所有这些步骤后,生成的类不会显示在项目资源管理器中。事实上,整个target目录是无处可见的。编译失败cannot find symbol: SomeClassFactory并new SomeClassFactory().create()在编辑器中标记为红色,而 Maven 生成和编译没有任何问题。
I'm out of options myself and any help or suggestions would be very welcome!
我自己别无选择,非常欢迎任何帮助或建议!
Update:when I comment the code that causes the compilation error, IntelliJ prints this warning in the compilation messages: Warning:Output path /Users/.../target/generated-sources/annotations intersects with a source root. Only files that were created by build will be cleaned.
更新:当我注释导致编译错误的代码时,IntelliJ 在编译消息中打印此警告:Warning:Output path /Users/.../target/generated-sources/annotations intersects with a source root. Only files that were created by build will be cleaned.
采纳答案by Rolf W.
I got help from Jetbrains support and the problem turned out to be a preference for excluded files. There are two places where these are configured:
我得到了 Jetbrains 支持的帮助,结果证明问题是对排除文件的偏好。有两个地方配置了这些:
Please check that folders/files are not excluded in
Preferences > Build, Execution, Deployment > Compiler > Excludesand the file/folder pattern in not listed inPreferences > Editor > File Types -> Ignored files and folders
请检查文件夹/文件未排除在中
Preferences > Build, Execution, Deployment > Compiler > Excludes,文件/文件夹模式未在中列出Preferences > Editor > File Types -> Ignored files and folders
In my case targetwas included in the ignored files and folders list in Editor> File Types.
就我而言target,它包含在Editor>中被忽略的文件和文件夹列表中File Types。
Then there was still a compilation issue, which I solved by throwing away the IDEA project files and creating the project again.
然后还是出现了编译问题,我把IDEA项目文件扔掉,重新创建项目解决了。


