IntelliJ forces me to define package in imported Eclipse and Maven project

Answered

I am trying to switch from Eclipse to IntelliJ due to a bug in coverage tests in Eclipse, so I tried importing my Eclipse project, which also uses Maven. After importing it seemed so far so good.

However, when inspecting the code there were errors everywhere about unresolved class names due to missing packages. I found out that the issue was that since my Maven project has a structure src/main, IntelliJ expected the packages to be main.old_packageinstead of what I just had, which worked perfectly in Eclipse.

I do not what that main package, it's just a folder, not a package. I also have an Application class under the main folder, just to try project functionalities as I develop it, but it is not under any package. However, the IDE demands a main package again.

I have been trying to work this out for a whole day but I just can't find a solution. I am sorry if this is a trivial question, but I don't know what else to try.

What can I do?

PS: I did solve it just so the project could compile, simply by prepending main or test to the packages under the src/main and src/test respectively, but this was just a temporary patch, I don't actually want to have a main or test package.

6 comments
Comment actions Permalink

Yes, it's the default, it's highly recommended to use this layout. Please consider moving your code to the standard directories.

1
Comment actions Permalink

Do you override the default src/main/java via pom.xml? Can you attach a sample to reproduce?

0
Comment actions Permalink

I am not sure... I am not much of a Maven expert, I just use it for dependency management. What would you need me to post?

0
Comment actions Permalink

If you are using default Maven configuration, sources must reside in src/main/java and test sources in src/test/java, see https://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html for details.

0
Comment actions Permalink

I am checking the pom.xml and src/main/java is mentioned nowhere. Does this mean it is in its default state? I had no issues in Eclipse though.

0
Comment actions Permalink

Ok so I changed the directories, removed src as a source directory, and marked both src/main/java and src/test/java as independent source directories, and it works. Thanks!

0

Please sign in to leave a comment.