在同一模块中使用时,IntelliJ无法找到生成的源 [英] IntelliJ can't find generated sources when used in same module

查看:2622
本文介绍了在同一模块中使用时,IntelliJ无法找到生成的源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用



我还执行了以下步骤:




  • 已验证 generated-sources 文件夹已添加为项目结构中的来源

  • 已验证Maven首选项生成的源文件夹设置为自动检测

  • 验证源是在重建时实际生成的(首先删除 target 文件夹,以确保它是由IntelliJ生成的)

  • 尝试在项目结构中禁用排除输出路径,如 @tilpner

  • 使缓存无效并重新启动

  • 删除 .idea 文件夹和 .iml 文件

  • 尝试的不同设置用于文件夹更新的阶段 in 首选项 - > Maven - > 导入



问题:



执行所有这些步骤后,生成的类没有不要出现我n项目探索者。事实上,整个目标目录无处可见。编译失败,找不到符号:SomeClassFactory
新的SomeClassFactory()。create()被标记为在编辑器中为红色,而Maven生成并编译没有任何问题。



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



更新:当我评论导致编译错误的代码时,IntelliJ会在编译消息中输出此警告:警告:输出路径/Users/.../target/generated-sources/annotations与源根相交。只清理由build创建的文件。

解决方案

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


请检查首选项>中是否排除了文件夹/文件。构建,执行,部署>编译器>排除首选项>中未列出的文件/文件夹模式。编辑>文件类型 - >忽略的文件和文件夹


在我的情况下目标包含在编辑器> 文件类型中的被忽略的文件和文件夹列表中。



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


I'm using annotation processors of Google's AutoFactory. I annotated SomeClass with @AutoFactory and referenced new SomeClassFactory().create() somewhere else in that same module.

Maven configuration:

I added the necessary dependency in Maven:

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

When running $ mvn clean compile I see that target/generated-sources/annotions/somepackage/SomeClassFactory is created and the module compiles without errors.

IntelliJ configuration:

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

This should be enough in my version of IDEA (v14.1.4) if my understanding is correct.

I also performed the following steps:

  • Verified that generated-sources folder is added as a source in Project Structure
  • Verified that Maven preference Generated sources folders is set to Detect automatically
  • Verified that source is actually generated upon Rebuild (deleted target folder first to be sure it's generated by IntelliJ)
  • Try to disable Exclude output paths in Project Structure, as suggested by @tilpner
  • Invalidate caches and restart
  • Delete .idea folder and .iml files
  • Experiment with different settings for Phase to be used for folders update in Preferences -> Maven -> Importing

Problem:

After performing all these steps, the generated class doesn't show up in the project explorer. In fact, the entire target directory is nowhere to be seen. Compilation fails with cannot find symbol: SomeClassFactory and new SomeClassFactory().create() is marked in red in the editor, while Maven generates and compiles without any problems.

I'm out of options myself and any help or suggestions would be very welcome!

Update: when I comment the code that causes the compilation error, IntelliJ prints this warning in the compilation messages: Warning:Output path /Users/.../target/generated-sources/annotations intersects with a source root. Only files that were created by build will be cleaned.

解决方案

I got help from Jetbrains support and the problem turned out to be a preference for excluded files. There are two places where these are configured:

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

In my case target was included in the ignored files and folders list in Editor > File Types.

Then there was still a compilation issue, which I solved by throwing away the IDEA project files and creating the project again.

这篇关于在同一模块中使用时,IntelliJ无法找到生成的源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆