immutables: Cannot find symbol: class Immutable
I have Immutables working fine in Eclipse with m2e-apt. But when I try to build the same project with mvn clean compile
, I get compile errors that start with “cannot find symbol: class Immutable” and continue with many more “cannot find symbol” errors because the class that should have been generated, let’s call it Foo
, by that @Immutable
wasn’t. The strange thing is that this @Immutable AbstractFoo
class is just one of many nested @Immutable
classes and the other classes are being generated fine. So the error, “cannot find symbol: class Immutable”, only for the declaration on AbstractFoo
doesn’t make sense because the @Immutable
declaration is the same as all of the others in the same file that are working.
I tried to reproduce the problem in a simpler test project, but I wasn’t able to. So I copied the main project src to the test project src and then the same compile errors appeared. I started deleting other classes that reference the should-be-generated Foo
and once they (and references to them) were deleted, the test project then compiled successfully. So it appears that the issue is related to other classes referencing the class that will be generated by an @Immutable
.
Does this make sense? Is this a bug that can be fixed or do I need to use a workaround? Am I wrong to reference generated classes or to create nested @Immutable
classes without using @Enclosing
?
About this issue
- Original URL
- State: open
- Created 9 years ago
- Comments: 15 (8 by maintainers)
Those are very valuable observations @DavidLeoni, thank you for finding it out! If we not take into account this particular compiler bug (as I think it is, but may be wrong), there’s currently that major point of disappointment which was mentioned is that having an early compilation error (could be related to missing type but not necessarily) then all to-be-generated-types are considered as missing whether they are generated or not. As about ‘duplicate class’ problem, have you tried using
<useIncrementalCompilation>false</useIncrementalCompilation>
, does it make any difference? (#134)To answer myself: after fiddling with maven I found out that doing a
mvn clean compile
and thenmvn compile
allows to get rid of the “cannot find symbol” messages and isolate real errors. But successivemvn compile
may show a lot of ‘duplicate class’ errors