Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Class already exists" error in IntelliJ on Groovy class

in IntelliJ (2016.2 and previous) we have our Groovy classes marked red with the error "class already exists". I think we can exclude that the cause is the stub-generation, as this is deactivated.

Probably it's caused in our constellation: We have included our compiled groovy (and java) classes in a jar that is registered as dependency.

Dependency MyProduct.jar contains com.mycompany.MyGroovyClass

Our source contains com.mycompany.MyGroovyClass

The error disappears if the dependency is registered with Test-Scope, in all other scopes the error appears.

However, in our structure we kinda have to include the compiled classes in a compile scope, as we want to avoid that each developer needs to compile all classes (I know about the compile in background ability, but we have a constellation that prevents this from working).

We have no errors in com.mycompany.MyJavaClass which exists as well in source and in MyProduct.jar.

Any ideas on how we can solve this?

like image 270
Ed O Neill Avatar asked Aug 02 '16 14:08

Ed O Neill


3 Answers

We've been suffering the same issue, it seems to be that IntelliJ registers the Java class, but also the Groovy class, and because of that it is showing that message (BTW, we are using a Maven Project).

So we ended up by going to the target folder -> right click -> Mark Directory As -> Excluded. Then, this setting will be saved on the IML file, and it won't happen again.

Hope it works for your as well! Cheers

like image 198
facundofarias Avatar answered Oct 11 '22 08:10

facundofarias


I'm using gmavenplus-plugin:1.5 After marking target/generated-sources/generated-sources/main as "Excluded", The error disappeared. I even did "invalidate cache and restart", It persists the setting. This is great. Intellij 2017.1.5

like image 35
brownfox Avatar answered Oct 11 '22 07:10

brownfox


We have two ways to fix this issue

  1. Exclude Stub Directory

target folder -> generated-sources -> groovy-stubs -> Right click main folder -> Mark Directory As -> Excluded

  1. Remove generateStubs goal from gmaven plugin

Remove <goal>generateStubs</goal> from gmavenplus plugin

like image 27
IamVickyAV Avatar answered Oct 11 '22 07:10

IamVickyAV