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

Rol*_* W. 13 java intellij-idea maven autofactory

我正在使用谷歌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>
Run Code Online (Sandbox Code Playgroud)

运行时,$ mvn clean compile我看到它target/generated-sources/annotions/somepackage/SomeClassFactory已创建,模块编译没有错误.

IntelliJ配置:

  • Reimport all maven modules
  • Preferences- > Annotation Processors- >Enable annotation processing
  • Rebuild Project

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

编译器首选项 项目结构

我还执行了以下步骤:

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

问题:

执行所有这些步骤后,生成的类不会显示在项目资源管理器中.实际上,整个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.

Rol*_* W. 15

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

请检查文件夹/文件是否未排除,Preferences > Build, Execution, Deployment > Compiler > Excludes文件/文件夹模式未列在Preferences > Editor > File Types -> Ignored files and folders

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

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