我正在使用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配置:
-
Reimport all maven modules
-
Preferences
- >Annotation Processors
- >Enable annotation processing
-
Rebuild Project
如果我的理解是正确的,那么在我的IDEA版本( v14.1.4
)中这应该足够了 .
我还执行了以下步骤:
-
已验证
generated-sources
文件夹已添加为Project Structure
中的来源 -
已验证Maven首选项
Generated sources folders
设置为Detect automatically
-
已验证源是在重建时实际生成的(首先删除
target
文件夹以确保它是由IntelliJ生成的) -
尝试在项目结构中禁用
Exclude output paths
,如@tilpner所示 -
使缓存无效并重新启动
-
删除
.idea
文件夹和.iml
文件 -
在
Preferences
中进行Phase to be used for folders update
的不同设置试验 - >Maven
- >Importing
问题:
执行所有这些步骤后,生成的类不会显示在项目资源管理器中 . 事实上,整个 target
目录无处可见 . 编译失败, cannot find symbol: SomeClassFactory
, new SomeClassFactory().create()
在编辑器中标记为红色,而Maven生成并编译没有任何问题 .
我自己没有选择,非常欢迎任何帮助或建议!
Update: 当我评论导致编译错误的代码时,IntelliJ在编译消息中输出此警告: Warning:Output path /Users/.../target/generated-sources/annotations intersects with a source root. Only files that were created by build will be cleaned.
1 回答
我得到了Jetbrains支持的帮助,结果问题是对排除文件的偏好 . 这些配置有两个地方:
在我的情况下
target
被包含在Editor
>File Types
中的被忽略的文件和文件夹列表中 .然后还有一个编译问题,我通过丢弃IDEA项目文件并再次创建项目来解决 .