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

2022-09-03 02:22:15

我正在使用Google AutoFactory的注释处理器。我在同一模块中的其他地方进行了注释和引用。SomeClass@AutoFactorynew SomeClassFactory().create()

配置:

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

    <dependency>
        <groupId>com.google.auto.factory</groupId>
        <artifactId>auto-factory</artifactId>
        <version>1.0-beta2</version>
        <optional>true</optional>
    </dependency>

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

IntelliJ configuration:

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

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

Compiler Preferences Project Structure

我还执行了以下步骤:

  • 已验证是否将文件夹添加为源generated-sourcesProject Structure
  • 已验证 Maven 首选项是否设置为Generated sources foldersDetect automatically
  • 已验证源代码是否确实在重建时生成(首先删除文件夹以确保它是由IntelliJ生成的)target
  • 尝试在项目结构中禁用,如@tilpner建议的那样Exclude output paths
  • 使缓存失效并重新启动
  • 删除文件夹和文件.idea.iml
  • 试验 in 的不同设置Phase to be used for folders updatePreferences -> Maven -> Importing

问题:

执行所有这些步骤后,生成的类不会显示在项目资源管理器中。事实上,整个目录无处可见。编译失败,并在编辑器中标记为红色,而Maven生成和编译没有任何问题。targetcannot find symbol: SomeClassFactorynew SomeClassFactory().create()

我自己没有选择,任何帮助或建议都非常受欢迎!

更新:当我注释导致编译错误的代码时,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支持部门得到了帮助,问题原来是首选排除的文件。在两个位置配置了这些:

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

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

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


答案 2

推荐