Eclipse和Gradle类路径不同步:无法解析为类型 [英] Eclipse and Gradle classpath out of sync: cannot be resolved to a type
问题描述
ProjectA
- src / main / java / ...
- build.gradle
ProjectB
- src / main / java / ...
- - build.gradle
$ b 在运行
gradle eclipse
并将项目导入Eclipse后,偶尔会得到'MyType can not我们的项目在他们的类路径中有Gradle库容器。 $ b $ b 这发生在整个团队中,我们无法弄清楚为什么Eclipse会继续下去g不同步,无法不时编译。通常解决这个问题的方法是:
其他注意事项:
- 使用Gradle 2.2.1版本
- Eclipse Luna和Eclipse Mars
- 使用JDK 8
在Eclipse中是否有其他类型的编译问题与Gradle项目?
这些问题的一个来源可以让Gradle生成Eclipse项目元数据/设置文件通过运行 gradle eclipse
)。我知道Maven和Gradle团队真的希望他们的工具(Maven或Gradle)能够生成这些东西,但是他们出色地做了一个不太理想的工作。例如,上次我使用Gradle时,它将.classpath配置为使用硬编码的JRE库路径,而不是首选的执行环境。这种糟糕的生成文件使开发人员头疼。
相反,Eclipse的建议是手动配置您的项目(大部分),只允许Gradle管理它的Classpath Container,然后检查Eclipse .project,.classpath和.settings文件/文件夹到你的SCM(svn,git等)中。这样,将项目签出到工作区的过程是自动的,不需要运行 gradle eclipse
或 mvn eclipse:eclipse
所有时间。
这就是Eclipse项目最初设计和打算进行管理的方式,并且工作得很好。我曾在非常大的项目(Eclipse中的100多个单独项目和数十个开发人员)上使用这样的设置。它也减少了从零到正在运行的应用程序的步骤数。
这是Maven / Gradle和Eclipse之间的哲学差异之一;当它归结为IMO时,IDE应该管理它的东西,并且构建/依赖关系工具应该保持不变。
尝试手动将事情做好在你的项目配置中,然后检查这些文件 - 看看它是否能减轻你的团队在这个领域面临的头痛。
We are having a frustrating problem with our Eclipse workspace. Here is a high-level example of what is happening:
ProjectA
-- src/main/java/...
-- build.gradle
ProjectB
-- src/main/java/...
-- build.gradle
After running gradle eclipse
and importing the projects into Eclipse, we occasionally will get 'MyType cannot be resolved to a type' even though the following are true:
- Our projects have the Gradle library container on their classpath
- The projects have the correct workspace projects within their Gradle container
- Things like CTRL + Click work from types that are showing up with red underline (i.e. compile error) meaning Eclipse knows exactly how to get to those types, but the compiler can't find them
- Command-line Gradle builds work as expected
This is happening throughout the team and we cannot figure out why Eclipse keeps going out of sync and cannot compile from time to time. What usually fixes the problem is a combination of:
- Project > Clean in Eclipse
- Gradle cleanEclipse or gradle eclipse
- Reimporting the projects
- etc
Other notes:
- Using Gradle version 2.2.1
- Happens in both Eclipse Luna and Eclipse Mars
- Using JDK 8
Has anyone else had these types of compile issues in Eclipse with Gradle projects?
One source of such problems can be letting Gradle generate the Eclipse project metadata/setup files (what you get by running gradle eclipse
). I know that the Maven and Gradle teams really want their tool (Maven or Gradle) to generate that stuff, but they notoriously do a less-than-ideal job of it. For example, the last time I used Gradle it configured the .classpath to use a hard-coded JRE library path instead of the preferred Execution Environment. That kind of poor job of generating files makes for developer headaches.
Instead, the Eclipse recommendation is to manually configure your projects (for the most part), only letting Gradle manage its Classpath Container, then checking in the Eclipse .project, .classpath, and .settings files/folders in to your SCM (svn, git, etc.). That way, the process of checking out a project into a workspace is automatic and does not require running gradle eclipse
or mvn eclipse:eclipse
all the time.
That's the way that Eclipse projects were originally designed and intended to be managed, and it works very well. I've worked with setups like that on very large projects (100+ separate projects in Eclipse and dozens of developers). It also cuts down on the number of steps to go from zero to running app.
This is one of those philosophical differences between Maven/Gradle and Eclipse; when it comes down to it, IMO, the IDE should manage it's stuff and the build/dependency tool should just stay out of the way.
Try manually getting things just right in your project configuration and then checking in those files - see if it doesn't relieve the headaches your team faces in this area.
这篇关于Eclipse和Gradle类路径不同步:无法解析为类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!