Yes, but the problem is that we won't know there are any duplicates until after compilation already starts. By this point, it is already too late to exclude resources.
I can see two possible solutions, neither of which I like:
- Create a kind of Grails builder, or maybe just a compilation participant that searches through the indexes and looks for duplicate types. And then tries to resolve which one it should use and which should be excluded before handing control over to the builder. This would be slow and there would be significant duplication of logic in the builder as there would be in the compiler.
- Create a callback in the compiler so that when this duplicate type problem is found, an exclusion filter is added. Then abort compilation and restart. This, too will take a long time (essentially compiling twice) and requires a change to the compiler.
Now that I think about it, there is a third possibility, which is slightly less bad than the other two:
After compilation is finished, search all problems for duplicate types. If there is one, then try to resolve the problem. Although this too, would require multiple compilation steps, at least we could take full advantage of the incremental compiler here.