在同一模块中使用时,IntelliJ无法找到生成的源

我正在使用谷歌AutoFactory的注释处理器。 我使用@AutoFactory注释SomeClass ,并在同一模块中的其他地方引用了new SomeClassFactory().create()

Maven配置:

我在Maven中添加了必要的依赖:

   com.google.auto.factory auto-factory 1.0-beta2 true  

当运行$ 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 )中这应该足够了。

编译器首选项 项目结构

我还执行了以下步骤:

  • 已validationgenerated-sources文件夹是否作为Project Structure的源添加
  • 已validationMaven首选项Generated sources folders设置为Detect automatically
  • validation源是在重建时实际生成的(首先删除target文件夹以确保它是由IntelliJ生成的)
  • 尝试按照@tilpner的建议禁用项​​目结构中的Exclude output paths
  • 使缓存无效并重新启动
  • 删除.idea文件夹和.iml文件
  • Preferences – > Maven – > Importing尝试使用Phase to be used for folders update不同设置进行Phase to be used for folders update

问题:

执行所有这些步骤后,生成的类不会显示在项目资源管理器中。 事实上,整个target目录无处可见。 编译失败, cannot find symbol: SomeClassFactorynew 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. Warning:Output path /Users/.../target/generated-sources/annotations intersects with a source root. Only files that were created by build will be cleaned.

我得到了Jetbrains支持的帮助,结果问题是对排除文件的偏好。 有两个地方配置这些:

请检查Preferences > Build, Execution, Deployment > Compiler > Excludes以及Preferences > Editor > File Types -> Ignored files and folders中未列出的文件/文件夹模式中是否Preferences > Build, Execution, Deployment > Compiler > Excludes了文件夹/ Preferences > Editor > File Types -> Ignored files and folders

在我的情况下, target包含在Editor > File Types中的被忽略的文件和文件夹列表中。

然后还有一个编译问题,我通过丢弃IDEA项目文件并再次创建项目来解决。

Interesting Posts