Eclipse file search finds the same file multiple times
Asked Answered
M

11

40

In Eclipse I have two maven projects A and B, where A is a parent for B. The directory structure is the following:

A/pom.xml
A/B/pom.xml
A/B/...

Then I use File search (Ctrl+H) to find any file in the project B. The search result window shows the file two times with different relative paths:

A/B/<my_file>
B/<my_file>

So, the same file is shown twice. Obviously, the first search result is reduntant. Is there a way to exclude these duplicate search results?

Mamba answered 25/2, 2013 at 10:25 Comment(6)
I don't see why you see the file in project A. I don't have the same behavior in Eclipse.Loser
Is your child project a subdirectory of the parent project? Are your projects m2e projects?Mamba
My projects are m2e projects, But the child is not a subdirectory of the parentLoser
Ok, I see, I thought you had some wierd source copy, but your child is a subdirectory of the parent. Then the answer posted (but deleted) by someone was correct, use the scope "selected resources" to perform your search.Loser
What if I don't know which resource contains my file?Mamba
Maybe using the scope "selected resources" on the parent can do the trick for you. Generally speaking, I don't like to have a project in a sub folder of a directory.Loser
D
45

What I personally do to avoid this is marking each module in the parent project as derived (right-click on the folder > properties > Attributes: Derived).

Then when you perform a file search, uncheck "Consider derived resources" (I don't think it is checked by default) and you won't get the A/B/<my_file>.

The only inconvenience is that you must do this for each module, and each time a new module is added.

Decerebrate answered 25/2, 2013 at 13:13 Comment(6)
Note that this solution doesn't work if you're using GIT since it keeps modifying the .gitignore file to exclude the "derived" projects.Soilasoilage
@DamonHorrell You can configure EGit to not automatically add derived files to the .gitignore file, in Eclipse Luna. In Preferences, go to Team > Git > Projects. Then uncheck 'Automatically ignore derived resources by adding them to .gitignore'.Front
With AutoDeriv plugin github.com/nodj/AutoDeriv you can automate derived resources in the way very similar to .gitignore. This plugin allows to define ".derived" file specially for Eclipse. In this way you can add all subprojects to ignore automatically.Barometry
Hi, Ryan Bennetts ... thanks for your post This is precisely the problem of eclipse. It has a hundred thousand options to configure every single aspect, because things just do not work properly. I wish netbeans would had more performance. Eclipse feels like a cascading mess. You have multiple resources in Mvn. Add the derive flag like above. Then Git stars ignoring modules. Go to preferences, tick option to disable auto add to git-ignore file. OMG! It never ends with eclipse. The thing is faster than netbeans and intelliJ but god... SIMPLIFY this mess!Eclipse itself has become a work-around!Dispossess
I think this answer is outdated (Eclipse 2023-03) ? Maven sub-modules are not folders but projects and don't have "Attributes" in Properties window. I will use @MarekM answer has working solution.Lusatia
@Lusatia it might well be outdated, as I haven’t used Eclipse for a long time, unfortunately. The thing is, if Eclipse now hides the sub-modules folders, I would assume the original issue of the question should be resolved.Decerebrate
A
21

In an open resource window (cntrl+shift+R), click on the arrow on top-right and check "Filter Duplicated Resources". This worked for me.

Ahmad answered 3/5, 2017 at 4:49 Comment(0)
H
18

Checking Window -> Preferences -> Maven -> Hide folders of physically nested modules (experimental) worked for me in Mars.1 Release (4.5.1).

After checking it I closed all projects within eclipse, deleted eclipse project files (.project, .classpath and .settings) and reimported my maven projects.

Humber answered 3/1, 2016 at 3:24 Comment(1)
Since Mars, from Project Explorer, on its view menu: Project Presentation > Hierarchical. However, this only applies to the Project Explorer, not to other views such as Search.Preglacial
R
6

I had similar problem.

My solution for this problem was

  1. Create eclipse "working set" of projects to search
  2. Set this working set as option into search dialog
  3. Search in it

    example search dialog

Rotberg answered 5/1, 2017 at 15:4 Comment(0)
S
4

Windows - Preferences - Maven - Hide folders of physically nested modules

Soilasoilage answered 9/9, 2014 at 2:55 Comment(1)
Since Mars, from Project Explorer, on its view menu: Project Presentation > Hierarchical. However, this only applies to the Project Explorer, not to other views such as Search.Preglacial
F
2

I agree with Damon Horrell. Go to Windows - Preferences - Maven - Hide folders of physically nested modules (make sure the checkbox is checked).

Note: Make sure to re-import the maven project into eclipse to see the changes.

Feleciafeledy answered 11/3, 2015 at 18:50 Comment(1)
Since Mars, from Project Explorer, on its view menu: Project Presentation > Hierarchical. However, this only applies to the Project Explorer, not to other views such as Search.Preglacial
F
2

Within the parent project, child ones were already visually hidden in my case, but still found through search and Ctrl-click links.

I solved this by using Resource filters:

  1. Right-click (parent) project > Properties > Resource > Resource Filters
  2. Click Add Filter..., select Applies to -> Folders and enter one child project's folder name, click OK
  3. Repeat 2. for all child project folders

By the end, you should have something like this:enter image description here

Footsie answered 31/8, 2017 at 6:56 Comment(0)
M
1

There is an ancient bug which requests Eclipse to support nested projects. Opened 2008, won't happen soon, I guess.

Since Eclipse doesn't support Maven's default nested module layout, you have to import each module individually which doesn't confuse Eclipse but it can confuse you as you can see in the search results. Similar things happen when you start to save launch configs in a module.

There are several possible solutions:

  1. Get used to ignoring half the search results. Takes some discipline but no magic.

  2. Make sure your root project doesn't contain anything important that you might want to open from Eclipse (i.e. move the parent POM to a new module which must be a child of the root project). Now you can close the root project.

    Takes some discipline where to put things in your project and it's clumsy when you have to add new modules.

  3. Use the flat multi-module approach. This is an extension to #2, it looks odd and there might be plugins that are offended by that. So if you use a lot of nonstandard plugins, you should check whether they like the new layout.

Macmahon answered 25/2, 2013 at 13:4 Comment(1)
FYI, there has been some progress recently concerning bug 245412: in release 4.5, projects will be visually nested in the project explorer. It does not fix the duplicate entries in the search dialog yet but at least there is some progress.Decerebrate
U
0

You can solve this problem using a flat multi-module approach.

Caveats may apply if you're using the maven-release-plugin with a version control system other than Subversion.

Unread answered 25/2, 2013 at 11:36 Comment(0)
E
0

As a new joiner, still couldn't comment but I'd really like to add something to the best answer. It works! It not only removed the duplicate files for me (one from child module and one from parent module), it also removed the class files from parent module).

But it added the folder to my .gitignore which will cause problem for new files/directories added later. I just reverted the change to .gitignore and it still works in eclipse.

Find this answer to disable auto change of .gitignore EGit and Eclipse modifies .gitignore file but it should not

Ellora answered 28/3, 2014 at 9:40 Comment(0)
G
0

In addition to "Hide folders of physically nested modules" mentioned, you could uncheck parent modules when importing Maven project: enter image description here

Glairy answered 29/8, 2020 at 6:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.