Eclipse Gradle dependencies are not updated in Web App Libraries - eclipse

I have a Gradle project (imported and generated using Eclipse's Gradle plugin) in Spring Tool Suite edition of Eclipse (3.2.0). It works most of the time, but sometimes, dependencies are getting out-of-sync between "Gradle Dependencies" and "Web App Libraries" in the project. Here is what I mean:
I define a compile dependency as following:
compile(group: 'com.mygroup', name: 'myClient', version: '0.2.1')
Then, after I do "Gradle -> Refresh All" I see that the dependency lib "myClient-0.2.1.jar" is in the list of the "Gradle Dependencies", and in the list under the "web App Libraries".
Now, after some time, I decide to use a newer version of this lib:
compile(group: 'com.mygroup', name: 'myClient', version: '0.2.2')
I again do "Gradle -> Refresh All", I also tried to refresh the project, re-build it, open/close the project and Eclipse, but what I see is:
The dependency under the "Gradle Dependencies" is indeed updated and is listed as "myClient-0.2.2.jar". But, the dependency under the "Web App Libraries" refuses to be updated and stays as "myClient-0.2.1.jar". this, obviously, wracks havoc to my app as now my code is not referencing correct newer classes and shows up all red in Eclipse.
One workaround that works sometimes is to nuke the whole project, and re-build it from scratch, but this is rather more radical than what I'd like to do :) And it does not work sometimes. It looks like I cannot explicitly control what goes into the "Web App Libraries" - so even though I see that a wrong lib is listed in the Project -> Properties -> Java Build Path -> Libraries -> Web App Libraries - I cannot change it there.
Any insight into this would be much appreciated,
Thanks!
Marina

I had the same problem.
Try a gradle cleanEclipseWtp eclipseWtp, this worked for me.
The WebApp libs will be up to date.
Best regards
Max

1)delete it without deleting contents on disk
2)Import ... Existing projects into workspace and import the gradle-example project back
3)the Gradle Dependencies container is named nicely
4)restart Eclipse
5)the Gradle Dependencies container of the gradle-example project has the weird name I'm reporting

Related

How do I get my Eclipse-Maven project to automatically update its classpath when I change a dependency in my pom.xml file?

I’m using Eclipse Mars with Maven (v 3.3). When I update a dependency in my pom (change the version), my Eclipse-Maven project doesn’t pick it up, even when I right click my project, and select “Maven” -> “Update Project.” I know this because I do not see compilation errors in the Eclipse Java editor that I see when I build the project on the command line using
mvn clean install
When I remove the project from the workspace and re-import it, then things get back to normal. However this is a cumbersome process. How do I get my Maven-Eclipse project to automatically detect changes in my pom and update the project libraries appropriately?
And yes, in the “Project” menu, “Build Automatically” is checked.
When you import the project into Eclipse, use Eclipse's own built-in Maven support (aka, m2e). I recommend against using mvn eclipse:eclipse as it doesn't give the best results (as you're seeing). Maven is a build and dependency management tool, not an IDE; expecting it to manage IDE-specific stuff is silly, in my opinion (I realize the Maven team thinks differently, that Maven should be responsible for managing your IDE, but that's nonsense).
So if you have the project available on your system, delete any Eclipse-specific files (typically just .classpath, .project, and folder .settings), they were generated by mvn eclipse:eclipse and you don't want them interfering with the "proper" import process described here. Then inside Eclipse, use File > Import > Maven > Existing Maven Projects to import the project. That should result in better integration between Eclipse and maven, including automatically updating the Eclipse build path when the pom is changed.
As a quick check, after doing the import that way, you should see a group called Maven Dependencies in the Libraries tab of the project's Build Path (in Properties dialog). Like this:
If you want the Eclipse project configuration to be automatically updated every time the pom is changed, there's a (experimental) setting for that under Preferences > Maven. Be aware that doing so might not be desirable, though - as mentioned in this feature request, it's a somewhat lengthy process that touches a bunch of stuff in the Eclipse Project; doing that automatically on every pom.xml change could end up being more trouble than it's worth.
Three Mandatory checks you should do for automatic update in your classpath
Your Repository is not in-sync with your Eclipse IDE, Please check the below settings in your IDE.
Right Click your any POM.xml from your IDE and check for the Maven profile which should be auto-activated. Also offline and Force update check box shouldn't be enabled. Please refer the below image.
Always check for your user settings which should reflect your local maven settings.xml, as shown in the below figure.
After performing all these checks, refresh your Eclipse Work-space to get these changes reflected.
Eclipse should be updating your classpath. If it's not, that implies something is going wrong.
It's hard to say what the problem could be exactly without knowing more about your project's pom.xml. More information might be necessary to solve the issue, but I'll just make a stab in the dark:
Open the .project file in your project's root folder and check the ordering of builders and natures there. It might be possible that some other nature on the project is also causing maven2Nature to fail. Move maven nature up and see if that helps any.
Alternatively you might be thinking that Eclipse does not update your dependencies because it does not add some some error indicators in the project that should be there with new dependencies. If that's the case try cleaning the current project (project>clean...). Maven in Eclipse does not necessarily trigger a full rebuild when dependencies are updated.
If none of this works, closing/opening the project might solve the issue quicker than re-importing.
What you wrote, should work. Did you check this:
does "pure" mvn install from terminal see your changes in POM?
maybe some Maybe plugin is buggy, cached some dependencies in target, and mvn clean install is needed
you can run Eclipse in a new workspace, and import your project there, sometimes it helps in case of such strange problems
instead of importing Maven project to Eclipse via m2eclipse, you can try to create Eclipse files via the old mvn eclipse:eclipse and see what happens then
does it work well when you try to import your Maven project to other IDE, the free IntelliJ Community Edition for example?
As a last resort, you can delete your current Eclipse installation and install a new version. When you add several plugins, they might interfere with one another and create weird behavior. After you do that, do not import your Maven project into your workspace, but rather create a new one and copy and paste the files that you had.

How do I refresh project dependencies using Buildship in Eclipse?

Eclipse Mars was recently released and I felt like trying it out. It listed tighter integration with Gradle as one of its features via Buildship.
With Luna I was using Gradle Integration for Eclipse (4.4) and I found this a lot easier to work with for what I was trying to do; I could add a Gradle "nature" to an existing project without needing to remove the project and re-import it as I did with Buildship, and it automatically put all dependencies that I declared in build.gradle within the project's classpath.
With Buildship, I didn't see any option to configure an existing project as a Gradle project and I couldn't find a way to make it include the dependencies I specified in the build script within the project's classpath.
I tried installing the original plugin (GIfE 4.4) for Eclipse Mars and after restarting Eclipse it automatically did all that for me again. What I'm wondering is if there's a way to do this all through Buildship alone because right now, although it all works, it's quite a funny setup. My project's dropdown menu looks like this:
Apart from looking a bit odd it is actually quite a nice setup, since it combines the automatic dependency management of GIfE with the ability to run Gradle tasks directly from Eclipse that Buildship provides.
Updating the dependencies that eclipse sees should then be as simple as:
right click on project -> gradle -> refresh all
Update in buildship 1.0.16
Currently you need to jump through the delete-and-import hoop the first time you use an existing gradle project with buildship. You can now use the Add Gradle Nature option:
right click on project -> configure -> Add Gradle Nature
“Refresh Gradle Project” is now also shown when right-clicking on any .gradle file as well as in the context menu of the Gradle editor. source
See update below However sometimes you may find that when your project was imported, it didn't get the new Project and External Dependencies classpath entry which you would normally be able to see in your Project Properties -> Java Build Path -> Libraries
If this is indeed missing, add the following to your project's .classpath file and all the gradle goodness should start working:
<classpathentry exported="true" kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
Update in buildship 1.0.16
Gradle classpath container is restored if missing
When converting an existing Eclipse Java project to Gradle, the Gradle classpath container was missing. It is now always added when a project is a Java project.
Incase for anyone, if you are not getting the
right click on project -> gradle
link after doing the steps mentioned in #PaulAdamson answer. Try this.
In your build.gradle add apply plugin 'eclipse';
Close the project in eclispe.
Run the gradle build from command line and then reopen the project in eclipse.
Now the gradle link should be available on right click.
I agree Buildship is a bit of a disaster. The documentation is extremely sparse with limited examples and minimal user guide. You would think documenting the transition from Gradle Integration for Eclipse (4.4) would be a no-brainer but I guess not. I also don't have a single clue how to use Buildship other than that I ran some tasks manually and it put fully qualified paths in my .classpath file. That's ridiculous considering many projects are shared through change control systems.
Currently there is no "Convert to Gradle project" implemented in Buildship. However, if you remove the project and reimport it using the Gradle import wizard you should see the same exact project with the proper nature and the classpath container.
On top of that, if you have a Gradle project in your workspace and update the dependencies in the build script, you can refresh the classpath container by right-clicking on the project and select Gradle > Refresh projects.
A similar problem you were facing was discussed in the Gradle forums: discuss.gradle.org/t/adding-dependencies-to-projects/10415.
We also have a bug dedicated for this feature request: bugs.eclipse.org/bugs/show_bug.cgi?id=465355. Please vote for it and share your thoughts there too.
Regarding to the documentation: It's true that we haven't provided an official documentation for the central Eclipse help system, but there are some resources explaining the current functionality:
The user documentation on GitHub
A Vogella tutorial
If you have already converted Java project to Gradle project but [RIGHT-CLICK]+Import (Then importing 'Existing Gradle Project') then your project should be of Gradle Nature.
If the project is of Gradle Nature then in .classpath file you will not see all the .jar dependencies as you see in normal java project, Instead you will see a single entry of:
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
To refresh dependencies you should do following:
[RIGHT-CLICK] + Gradle + Refresh Gradle Project
This will fix all complication issues.

Maven integration into eclipse, Problems with Dependencies vs. Referenced Libraries

he fellas, i need your help again.
Im trying to develop a new part for an existing software. The parts are all done using Maven. I have to work in several projects at once, which are all continously opened in Eclipse. In Eclipse i use M2E, but i tend to edit the poms directly in xml.
So, now I can build (clean install) the projects individually, works ok. But Eclipse now has problems with the online help: It shows me errors. Eclipse cant seem to see classes which are placed in the same project, but different packages. Note that it works fine when i compile it!
Also after I run the pom the dependencies dont show up as "Maven Dependencies" but as "Referenced Libraries".
This persists after I run mvn eclipse:eclipse from outside and refresh.
Thanks so much for your help!
"Do not ever do mvn eclipse:eclipse", only do mvn eclipse:clean from command line first and then import "as maven projects" using your eclipse M2E plugin.
M2E Plugin knows how to handle Maven Dependencies, whereas mvn eclipse:eclipse knows how to handle Referenced Libraries, and they are NOT compatible with each other. You can always do mvn update project in Eclipse after mvn eclipse:clean.
I had to delete the maven-project, too, after using eclipse:eclipse. It added the references as "Referenced Libraries".
Manually deleting the .project and .settings files in the project folder and importing the project again helped. I used the M2E import. Afterwards it displayed the libraries within the "Maven Dependencies". Subsequently I was able to run it on my local webserver.
I do not really know the reason for the behavior, but deleting the project and reimporting it solved it.
I agree with kisna. As an alternative to fix the project if already contains both "Referenced Libraries" and "Maven Dependencies", you can do the following:
https://docs.oracle.com/cd/E14545_01/help/oracle.eclipse.tools.weblogic.doc/html/j2eelib/operations/opRemoveLibRefFromClasspath.html
Right-click on the project and select Properties -> Java Build Path -> Libraries tab -> Find the entry in the list of libraries called Shared Library [] or/and all libraries that starts with 'M2_REPO/', and then select it/them and remove.

GWT - Refreshing changes with 'Development Mode' with Maven

If I use GWT's Development Mode with Eclipse, changes that I make in the IDE are immediately reflected in my browser upon refresh. However, I can't seem to get the same result when using the maven plugin to build. Is this possible?
Here's what I've tried:
Running gwt:run, making a change and saving it in Eclipse, refreshing the browser.
Same as above but clicked the 'restart server' button on the GWT Development Mode console.
Telling Eclipse that my project is a GWT project and configuring a Web Application, but it fails to list any Entry Point Modules for me to choose from.
'webAppCreator -templates maven com.xx.WebApp' - creates just a pom, no project (?).
The only option seems to be: stop the console, gwt:compile, gwt:run. This cycle takes minutes each time..
Any ideas on how to achieve this, or if it's even possible? Not being able to do this is really a show stopper for us adopting GWT, since we can't scrap maven.
TIA, Roy
The real answer to this question came from Thomas Broyer's comment, but I wanted to spell out all of the steps that I took for future reference:
With Maven:
Create the project using the gwt maven plugin archetype.
Move the xxx.gwt.xml file from the 'resources' tree to the 'java' tree, as recommended by Thomas.
Run 'mvn clean install' to ensure that all's well, and to generate the async classes.
To get around this issue, add this to your pom. When you change your maven dependencies you'll need to run a maven compile to get them to take in Eclipse.
With Eclipse:
Import the project into Eclipse using 'Import Existing Maven Project'
Right-click on target -> generated-sources -> gwt, and select Build Path -> Add to Build Path.
In project properties -> Google -> Web Toolkit, 'Use Google Web Toolkit' is checked.
On the same page, add your entry point modules.
In project properties -> Google -> Web Application, ensure that 'This project has a WAR directory' is checked, and the dir points to 'src/main/webapp'
Right-click on the project, select Run As -> Web Application
Ready to go!

How to get peer project source in eclipse and maven

creating a parent project with only a pom.xml, and lots of sub projects such as:
my-web
my-core
my-backoffice
etc. is easy, and the sonotype eclipse plugin does most of the work.
However, getting one project to know about the source in the other project seems to be hard. E.g. when you are debugging the my-web project, and step into my-core, eclipse doesnt know where to get the source.
Looking in the Java Build Path in eclipse, the maven plugin has added my-core as a folder under "Web App Libraries". I.e. its not using the my-core-0.0.1.SNAPSHOT.jar or similar, its using the raw java files. Great!
But how to tell maven to tell eclipse to look for the source in the same place?
Im not really sure where to start. Im guessing its possible to get maven to put the source in a special jar using the maven-soure-plugin, but this will usually be out of sync with the actual java files which the web project seems to be using directly.
A quick and dirty solution is to manually Edit the Java Build Path for each project, and add my-core and other dependant projects in the "Projects" tab. Is this best practice? Any other suggestions?
A quick and dirty solution is to
manually Edit the Java Build Path for
each project, and add my-core and
other dependant projects in the
"Projects" tab.
If this doesn't happen automatically you have a configuration problem.
My Guess would be that you have a version mismatch between the pom dependencies and the actual project versions. Or your projects have an unusual name template (m2eclipse resolves projects by their artifactId AFAIK)
Either way, what always helps is in your Debug configuration (Run > Debug Configurations ...) select the Source tab and just Add... the selected projects.