I am periodically experiencing the "type [blah] cannot be resolved. It is indirectly referenced from required .class files"
error, and reaching out for help.
I've searched this site and the web, and all of the many similar-sounding questions seem to be resolved by adding classes to the classpath. But in this case, I'm pretty sure they already are on the classpath.
Here's the situation, pared down from an extremely large metaproject. There are two eclipse projects ProjectOne and ProjectTwo.
Both projects are published by a build server to an Ivy repository, and ProjectTwo's ivy.xml refers to that version of ProjectOne. However, I keep the ivy "resolve dependencies in workspace" preference turned on, so that I can work in both projects, and resolve to my modified classes instead of the published ones.
ProjectOne compiles in my workspace (as does ProjectTwo, except (occasionally) for the "indirectly referenced from required .class files" problem.
The structure looks basically like this:
// ProjectOne
class Enum { **// I now suspect this name is the problem**
public static class EnumObjectCache {
}
// ProjectTwo
class Bar { **// Occasionally gets error about Enum$EnumObjectcache being unresolvable**
}
This is despite the facts that:
- This only affects Eclipse. The real compiler handles this all with no problem
- ProjectTwo's ivy.xml file does contain a transitive dependency on ProjectOne.
- ProjectOne is present in the workspace, and successfully compiles.
- I always have "resolve dependencies in workspace" turned on.
- Regardless of how things are resolved, it should work class Enum (and EnumObjectCache) have been unchanged for more than a year.
- As an experiment, I've tried directly adding ProjectOne to ProjectTwo's classpath (by defining it as a required project). No change.
- To make this more interesting, this problem doesn't happen all the time, and it only happens to a few classes in this very large codebase. Oh, and when it does happen, it's always on Enum$EnumObjectCache.
- It doesn't happen to every one of the developers on the team at a time.
The problem, when it happens, persists over multiple 'clean' and restarts of eclipse, and IVY re-resolves. (though I wasn't doing Ivy clean-all-caches).
10. I can "fix" the problem by introducing an otherwise unneccssary import of Enum from ProjectOne
Note: I had not previously tried cleaning the cache, as it's painfully slow to do (remote cache is transatlantic, and it's a very large project): 55 minutes to clean all caches and re-resolve, then another 20 or so to rebuild.
However, following a clean-all-cache, re-resolve, and rebuild, I still have the same problem.