我正在使用 Google's AutoFactory 的注释处理器.我用 @AutoFactory
注释了 SomeClass
并在同一个模块的其他地方引用了 new SomeClassFactory().create()
。
Maven 配置:
我在 Maven 中添加了必要的依赖:
<dependency>
<groupId>com.google.auto.factory</groupId>
<artifactId>auto-factory</artifactId>
<version>1.0-beta2</version>
<optional>true</optional>
</dependency>
当运行 $ mvn clean compile
时,我看到 target/generated-sources/annotions/somepackage/SomeClassFactory
被创建并且模块编译没有错误。
IntelliJ 配置:
重新导入所有 maven 模块
首选项
->注释处理器
->启用注释处理
重建项目
如果我的理解是正确的,这在我的 IDEA 版本 (v14.1.4
) 中应该足够了。
我还执行了以下步骤:
- 已验证
generated-sources
文件夹已作为源添加到Project Structure
- 已验证 Maven 首选项
Generated sources folders
设置为Detect automatically
- 已验证源实际上是在重建时生成的(首先删除了
target
文件夹以确保它是由 IntelliJ 生成的) - 按照 @tilpner 的建议,尝试在项目结构中禁用
Exclude output paths
- 使缓存失效并重启
- 删除
.idea
文件夹和.iml
文件 - 在
Preferences
->Maven
->Importing
中对Phase to be used for folders update
的不同设置进行实验>
问题:
执行所有这些步骤后,生成的类不会显示在项目资源管理器中。事实上,整个target
目录都不见了。编译失败并显示 cannot find symbol: SomeClassFactory
并且 new SomeClassFactory().create()
在编辑器中被标记为红色,而 Maven 生成和编译没有任何问题。
我自己没有选择,非常欢迎任何帮助或建议!
更新:当我注释导致编译错误的代码时,IntelliJ 在编译消息中打印此警告:Warning:Output path/Users/.../target/generated-源/注释与源根相交。只会清除由构建创建的文件。
最佳答案
我得到了 Jetbrains 支持的帮助,结果发现问题出在对排除文件的偏好设置上。这些配置有两个地方:
Please check that folders/files are not excluded in
Preferences > Build, Execution, Deployment > Compiler > Excludes
and the file/folder pattern in not listed inPreferences > Editor > File Types -> Ignored files and folders
在我的例子中,target
包含在 Editor
> File Types
中忽略的文件和文件夹列表中。
然后还有一个编译问题,我通过丢弃IDEA项目文件并重新创建项目解决了这个问题。
关于java - 在同一模块中使用时,IntelliJ 找不到生成的源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33260148/