Eclipse can't resolve transitive dependency projects? - eclipse

In a Java project in Eclipse, I am trying to debug project A.
Project A has a dependency on B.jar, normally B.jar comes from my .m2/repository.
but now I want to make some temp changes to B's code, and have it reflected in A,
so I directly edit the source code in B project in eclipse, and set B as a dependency project in A's build path. Additionally, both A and B refer to C.jar as their dependencies.
This builds A fine, but when it is run, A's classpath contains 2 copies of all the classes and resources in C.jar. this creates a problem for those hibernate hbm.xml mapping files in C.jar and I got errors saying duplicate mapping for...
This looks to be a defect in eclipse, in that it lacks the resolution ability as maven posseses. is there a way to work around this? (apart from building B and installing to .m2 instead of having it as a dependency project)
Thanks

You mentioned "[setting] B as a dependency project in A's build path" - do you mean editing eclipse's build path or editing the project's POM? I'm guessing the former, in which case make sure that you have the latest version of the m2eclipse plugin installed and that both projects A & B are Maven eclipse projects. If it is set up correctly then your projects should look have an 'M' on their project icons, and the icons of any workspace dependencies should look like folders.

Related

Eclipse Mars, open type reference

I have project A and project B in Eclipse Mars.
Project A is packaged and used as dependency in project B's classpath (Eclipse's build path).
I mostly work from project A, the annoying thing is that when i want to open a type within project A with the Ctrl+Shift+T combination, it opens the compiled type in A's dependency of project B.
This page does not show anything about this.
any advice?
Rather than include ProjectA's package (JAR?) on ProjectB's build path, you should instead make ProjectB depend on ProjectA.
Open ProjectB's properties and then add the dependency here:
Don't forget to remove the ProjectA JAR from ProjectB's build path (in the Libraries tab above).

Counterclockwise in Eclipse Luna fails to see resources of a dependant project

I have a project A that depends on project B. The poject B is a subproject of A and works as a part of project A. The project B has its own resources that it must access to bootstrap itself. So, when I start the project A, it fails with the exception that the assets for project B cannot be found.
This setup worked just perfectly in Kepler, it did not have any issues with finding the files, so all paths and source folders are intact.
Looks like something has changed in Luna, comparing to Kepler. Does anyone have an idea on how to fix this?
EDIT: I also must add that the folder named "assets" exists in both project A and project B (they contain different assets). When I try to manually add the assets folder of project B to project A, Eclipse says that this folder already exists. Could this be the source of the problem? How do I resolve it then? Again, Kepler had no issues with that..
Thanks to #erhun, I have spotted the reson and the fix for the situation. As #erhun have queried, the project did not launch with Leiningen outside Eclipse with the very same issue. So it turned out that Counterclockwise was set to run the projects with Leiningen instead of the "defult java launcher", so I have changed it in the preferences and Eclipse did the magic.
Leiningen is known for its more strict policy on dependant projects, so it would not allow for such a kind of transitive dependancy, effectively making the user to copy all the resources into the main project.

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.
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
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.

Maven build is successful, Eclipse detects cycle in dependencies

I'm working on a large project that consists of many smaller projects (about 140) that are all managed by maven. There is a master pom and a pom for each individual project.
Now I have introduced 2 new small projects, A and B, with the dependency A -> B. Furthermore B depends on another existing project C, so B -> C. A is used by another project D which is (as far as I've seen) independent from C. I'm not sure because the structure is very complex and I don't want to sit there sifting through poms all day.
This means I have a dependency graph like this: D -> A -> B -> C
When I build the master pom in maven (clean install) it finishes successfully. So does the eclipse:eclipse goal that generates the Eclipse project files. When I refresh the projects in Eclipse it rebuilds everything and finishes with the error "A cycle was detected in the build path of project...". This error occurs in about 30 of the 140 projects. Ofcourse Eclipse doesn't tell me what the cycle looks like...
How can it be that maven does not detect a cycle in the dependencies but eclipse does? I thought that the Maven Eclipse plugin just mapped the dependencies from the pom to the Eclipse .project and .classpath files?
The fact that Maven doesn't complain about cycles tells me that there is no dependency C -> D.
I had the same symptoms but with no actual maven cycle. I dealt with this in eclipse Indigo in a workaround fashion: I closed and deleted the eclipse projects that reported this error (not deleting the files making up the project), then re-created the maven projects in eclipse by importing the source files into my workspace with "File->Import...->Maven->Existing Maven Projects". That took care of it.
You may have dependencies with the scope test or runtime. Maven only looks for cycles in the compile phase. Eclipse or m2e doesn't differ the dependencies in scopes.
You probably have previous Eclipse settings on your projects, try this steps:
Remove all projects from Eclipse.
Run 'mvn clean eclipse:clean;' from the console or delete all hidden files from all project folders: .project, .classpath, .wtpmodules, org.eclipse.core.resources.prefs, ...
Reimport the projects into Eclipse
This may fix the problem!

Maven project in eclipse - deployment assembly fails build

Sorry for being verbose...
I have some existing maven projects. I imported them into Eclipse using Maven -> Import existing Maven projects.
This gave me 6 individual projects and one project which lists all 6 under it. (The umbrella project has 6 modules defined in it which translated to 6 eclipse project - as I understand how maven works)
One of the project A requires two other project B and C (at compile time and run-time).
Build path -
On the build path of A I have one of the libraries as Maven dependencies. And it builds fine.
Deployment assembly -
On the deployment assembly of A however there is no entry for deploy to web-inf/lib. Because of that when tomcat starts it doesn't find any required jars or the project B and C.
So I added an entry to deployment assembly as : source - maven And dependencies deploy - web-inf/lib.
Tomcat comes up and my webapp for project A comes up.
This however breaks the eclipse build - upon build eclipse complains:
"Invalid classpath publish export Project entries not supported"
This I see is because, under build path, there is new entry added to web-inf/lib to publish/export under maven-dependencies. Removing that removes maven entry from the deployment assembly as well.
The only workaround is that in the deployment assembly I specify the web-inf/lib under target generated by maven but that causes stale copies of project B and C to be picked up.
Why I need this setting is because when I make changes to project B and C in Eclipse and build them in Eclipse I want to see the changes when I am debugging project A. I don't want to run maven builds on B and C again since its time consuming.
Any help is much appreciated.
I did try including the MAVEN2_CLASSPATH_CONTAINER but that is always empty and when tomcat runs it cannot find the necessary libraries. (BTW what vale is the MAVEN2_CLASSPATH_CONTATINER set to?)
This is on Eclipse Indigo Mac OSX.
You need to add the relevant project/s to your Deployment Assembly.
Right Click Project -> Properties -> Deployment Assembly -> Add
I solved just doing this:
right click on my eclipse project-> Maven -> Update Project Configuration...
Figured it out ..but not completely...
So I added maven dependency in the deployment assembly as I mentioned earlier.
Maven dependency -> WEB-INF/lib
AND additionally added project B and C as well :
B -> WEB-INF/lib and C->WEB-INF/lib
Somehow this way B and C are not added to the publish/export in the java build path. I don't know how eclipse knows to not export B and C from maven repo but to export it from project B and C itself.
Anyways thats for some other day..
for now i m happy :)
For anyone else that searches for this, it seems that you can also manually add the following to the .classpath file
<classpathentry combineaccessrules="false" kind="src" path="/B"/>
By including Maven Dependencies, you are including dependencies for project B and project C. It turns out, you also have to include project B and C manually.
The exact fix which works is.
project A -> properties -> Deployment Assembly
Click Add and then Project. Select B and C. Problem will get fixed after rebuilding.
I had this problem, but I believe none of these answers correctly fix the problem. Instead they workaround m2eclipse (which should manage classpaths and deployment assembly for you). For me, the problem that I was using m2eclipse without m2eclipse-wtp (a separate plugin).
See this SO answer for the plug-in details.
You can add the relevant projects / or maven java build path entry if using maven to your Deployment assembly (project -> properties -> deployment Assembly)
Then checks if theses relevant project are Facets compatible. (project -> Project Facets)
This error can occur if you have multiple entries of same jar in you class path. So you need to check your classpath and remove duplicate entries.