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

时间:2015-10-21 13:05:22

标签: java maven intellij-idea autofactory

我正在使用Google's 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 modules
  • Preferences - &gt; Annotation Processors - &gt; Enable annotation processing
  • Rebuild Project

如果我的理解是正确的,那么在我的IDEA版本(v14.1.4)中这应该足够了。

Compiler Preferences Project Structure

我还执行了以下步骤:

  • 已确认在generated-sources
  • 中添加了Project Structure文件夹作为来源
  • 已确认Maven偏好Generated sources folders已设为Detect automatically
  • 验证源是在重建时实际生成的(首先删除target文件夹,以确保它是由IntelliJ生成的)
  • 尝试按照@tilpner
  • 的建议在项目结构中停用Exclude output paths
  • 使缓存无效并重新启动
  • 删除.idea文件夹和.iml文件
  • Phase to be used for folders update - &gt;中尝试Preferences的不同设置Maven - &gt; 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.

1 个答案:

答案 0 :(得分:14)

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

  

请检查Preferences > Build, Execution, Deployment > Compiler > Excludes中未排除的文件夹/文件以及Preferences > Editor > File Types -> Ignored files and folders

中未列出的文件/文件夹模式

在我的情况下,target包含在Editor&gt;中已忽略的文件和文件夹列表中File Types

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