somelinesofcode
somelinesofcode

Reputation: 11

In Eclipse, how do I exclude test folder of one maven project from another project that has as a dependency?

I have two maven projects imported into Eclipse in the same workspace. Both have a class with the same name and package, but different implementations and in different locations in each project. Let's call this class com.namespace.Factory

Project A has Factory under its test folder, i.e: /src/test/java/com/namespace/Factory.java

Project B has Factory under its main source folder, i.e: /src/main/java/com/namespace/Factory.java

There is also a Project C which is dependent on both. Project C also uses Factory from Project B for some of its unit tests. Problem now is Eclipse can't compile Project C because it can't differentiate between the two Factory classes. If I build all projects in command line, they don't have issues.

You would think that Eclipse would ignore the Project A Factory class since it is in test.

I am using the m2e plugin. My current work around is to setup m2e to not resolve Project C's dependencies within the workspace. This forces it to download the jar that will not have test in it. However, this means I have a change in either A or B, I have to manually install A or B push the latest jar to the local repo, and update Project C's dependencies to pull down the latest jars.

Is there a way to exclude the Project A test folder from the build path in Project C so that I can continue resolving everything within the workspace? It feels like Eclipse is breaking something that is fundamental to maven projects.

Upvotes: 1

Views: 1228

Answers (2)

inor
inor

Reputation: 2846

Perhaps you can try this: In project A's Properties dialog (get there by right clicking the project and then click Properties),
click Deployment Assembly on the left.
Eclipse will show all source folders.
Select the test folder (/test) and click Remove.

Upvotes: 0

Peter Butkovic
Peter Butkovic

Reputation: 12129

I think you're just another user affected by the upstream bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=376616

To sum it up, the bug report discussion includes:

JDT implements just one buildpath per Eclipse project. This is very unlikely to change, since this was fundamental design choice and many APIs and implementation details rely on that.

Well, but that doesn't really answer your question I guess. So I see multiple options here, depending on how much influence you might have on the projects:

  • either try to rename one of the classes => names would be unique
  • or if the classes contain basically the same functionality, play with dependencies between projects, or even create new one, that the other 2 would depend upon
  • that's pretty much what comes to my mind right now

Upvotes: 2

Related Questions