我正在使用Google 的 AutoFactory 的注释处理器。我在同一个模块的其他地方进行了注释SomeClass和@AutoFactory引用。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 modulesPreferences->Annotation Processors->Enable annotation processingRebuild Project
v14.1.4如果我的理解是正确的,这在我的 IDEA ( ) 版本中应该足够了。
我还执行了以下步骤:
- 已验证
generated-sources文件夹已添加为源Project Structure - 已验证 Maven 首选项
Generated sources folders设置为Detect automatically - 验证源实际上是在重建时生成的(
target首先删除文件夹以确保它是由 IntelliJ 生成的) - 按照@tilpner的建议,尝试
Exclude output paths在项目结构中禁用 - 使缓存无效并重新启动
- 删除
.idea文件夹和.iml文件 - 尝试不同的设置
Phase to be used for folders updateinPreferences->Maven->Importing
问题:
执行所有这些步骤后,生成的类不会显示在项目资源管理器中。事实上,整个target目录无处可寻。编译失败cannot find symbol: SomeClassFactory
并new SomeClassFactory().create()在编辑器中标记为红色,而 Maven 生成和编译没有任何问题。
我自己没有选择,非常欢迎任何帮助或建议!
更新:当我注释导致编译错误的代码时,IntelliJ 在编译消息中打印此警告:Warning:Output path /Users/.../target/generated-sources/annotations intersects with a source root. Only files that were created by build will be cleaned.

