在同一模块中使用时,IntelliJ 找不到生成的源
IntelliJ can't find generated sources when used in same module
我正在使用 Google's AutoFactory 的注释处理器。我用 @AutoFactory
注释了 SomeClass
并在同一个模块的其他地方引用了 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
-> Annotation Processors
-> Enable annotation processing
Rebuild Project
如果我的理解是正确的,这在我的 IDEA (v14.1.4
) 版本中应该足够了。
我还执行了以下步骤:
- 已验证
generated-sources
文件夹已作为来源添加到 Project Structure
- 已验证 Maven 首选项
Generated sources folders
设置为 Detect automatically
- 已验证源实际上是在重建时生成的(首先删除了
target
文件夹以确保它是由 IntelliJ 生成的)
- 按照@tilpner
的建议,尝试在项目结构中禁用Exclude output paths
- 使缓存无效并重新启动
- 删除
.idea
个文件夹和 .iml
个文件
- 在
Preferences
-> Maven
-> Importing
中对 Phase to be used for folders update
进行不同设置的实验
问题:
执行所有这些步骤后,生成的 class 不会显示在项目资源管理器中。事实上,整个 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.
我得到了 Jetbrains 支持的帮助,结果发现问题出在对排除文件的偏好设置上。这些配置有两个地方:
Please check that folders/files are not excluded in Preferences > Build, Execution, Deployment > Compiler > Excludes
and the file/folder pattern in not listed in Preferences > Editor > File Types -> Ignored files and folders
在我的例子中,target
包含在 Editor
> File Types
.
中忽略的文件和文件夹列表中
然后还有一个编译问题,我通过扔掉IDEA工程文件重新创建工程解决了。
我正在使用 Google's AutoFactory 的注释处理器。我用 @AutoFactory
注释了 SomeClass
并在同一个模块的其他地方引用了 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
->Annotation Processors
->Enable annotation processing
Rebuild Project
如果我的理解是正确的,这在我的 IDEA (v14.1.4
) 版本中应该足够了。
我还执行了以下步骤:
- 已验证
generated-sources
文件夹已作为来源添加到Project Structure
- 已验证 Maven 首选项
Generated sources folders
设置为Detect automatically
- 已验证源实际上是在重建时生成的(首先删除了
target
文件夹以确保它是由 IntelliJ 生成的) - 按照@tilpner 的建议,尝试在项目结构中禁用
- 使缓存无效并重新启动
- 删除
.idea
个文件夹和.iml
个文件 - 在
Preferences
->Maven
->Importing
中对
Exclude output paths
Phase to be used for folders update
进行不同设置的实验
问题:
执行所有这些步骤后,生成的 class 不会显示在项目资源管理器中。事实上,整个 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.
我得到了 Jetbrains 支持的帮助,结果发现问题出在对排除文件的偏好设置上。这些配置有两个地方:
Please check that folders/files are not excluded in
Preferences > Build, Execution, Deployment > Compiler > Excludes
and the file/folder pattern in not listed inPreferences > Editor > File Types -> Ignored files and folders
在我的例子中,target
包含在 Editor
> File Types
.
然后还有一个编译问题,我通过扔掉IDEA工程文件重新创建工程解决了。