I am having trouble deleting an external dependency from my build path. I have searched this site and the web but have not found a good answer.
I use gradle 4.9 and eclipse 4.7.3a to manage my automated tests. I have placed external jars in a folder named artifact in a git project's root directory.
My build.gradle file contains this line in the dependencies section:
compile fileTree(dir: "./artifact", include: '*.jar')
Well and good, it all works. However, when I try to delete a dependency using
Build Path > Configure Build Path... > Libraries > Project and External Dependencies
all the buttons, including Remove, are grayed out.
I can delete the file from the artifact directory and issue
gradle cleanEclipse
from the command line but when I open Eclipse and try to open the project (under Project Explorer) I get 'Open Project' has encountered a problem. The project description file (.project) for 'project name' is missing.
After replacing the old jar with the new version (different file name of course), I tried running
gradle
which is supposed to recreate configuration files deleted by cleanEclipse. No joy. Next, I tried running
gradle build
But after restarting eclipse, still a failure. The only thing that worked was to delete the project from eclipse and then to re-import it.
Is there an easier way?
Thank you.
Well, I found an answer.
After deleting and copying in the new jar file into the artifact directory, in eclipse, I selected Project > Clean ...
Then I right-clicked on the project and selected Gradle > Refresh Gradle project
I guess writing the question got me thinking about how eclipse handles .project files. Maybe this will help the next person.
Related
I have a problem with Eclipse: whenever I click Gradle > Refresh Gradle Project to refresh my Gradle dependencies, Eclipse deletes all of the external JARs in my build path. This happens with every Gradle project, and reinstalling Eclipse doesn't fix the problem.
The "Refresh Gradle Project" option:
Before and after refreshing:
Any idea how to fix this? Thanks in advance.
Yes, that is the expected behavior: Refresh Gradle Project resets the dependencies to the ones specified in the build.gradle file. So it overwrites your manually made changes in the Java Build Path.
In a Gradle project, instead of changing the Java Build Path settings directly, add all dependencies via the build.gradle file.
I can not post comment yet.
Did you check the gradle setting for repo locations ?
Eclipse may not able to get the jars from the repo.
and also did you try
gradle eclipse
to refresh the eclipse dependencies from command line, and refresh the project in eclipse.
In Eclipse Neon, I did an 'import existing maven project' from a local folder, whose content was copied from another machine. The project is not reading the dependencies on the POM file, and one example is the log4j dependency. A workaround is to add the log4j-1.2.17.jar manually to the project as an external jar, but this is wrong. Does anyone have tips on how to troubleshoot? I am fairly inexperienced with maven so I m not sure if there are additional settings or configuration that I have do when importing an existing project into eclipse.
You can make sure if your project dependencies are being pulled correctly or not by executing
mvn clean install
from within the project directory on the command line. This would download the required dependencies of the project as well.
The most common cause I have seen for this issue occurs whenever Maven encountered an error while downloading an artifact from a repository. In this case, Maven marks the download as failed and won't retry until some time elapses (I do not remember how long).
The easiest way to test this is to delete the .m2/repository folder in your home directory and let Maven download the artifacts again. If you have Maven installed you just execute "mvn install" from a console. Otherwise, you can try:
Right click the project in Eclipse
Select "Maven > Update Project"
Check "Force Update of Snapshots/Releases"
Click "OK"
Synchronize Gradle projects with workspace failed due to an unsupported configuration in the referenced Gradle build.
Project at '/home/jsiddharth/workspace/v2/mnoxwebservicesv2' can't be named 'mnoxwebserviceendpoints-..' because it's located directly under the workspace root. If such a project is renamed, Eclipse would move the container directory. To resolve this problem, move the project out of the workspace root or configure it to have the name 'mnoxwebservicesv2'.
org.eclipse.buildship.core.UnsupportedConfigurationException: Project at '/home/jsiddharth/workspace/v2/mnoxwebservicesv2' can't be named 'mnoxwebserviceendpoints-..' because it's located directly under the workspace root. If such a project is renamed, Eclipse would move the container directory. To resolve this problem, move the project out of the workspace root or configure it to have the name 'mnoxwebservicesv2'.
at org.eclipse.buildship.core.workspace.internal.DefaultWorkspaceOperations.validateProjectName(DefaultWorkspaceOperations.java:183)
at org.eclipse.buildship.core.workspace.internal.ProjectNameUpdater.checkProjectName(ProjectNameUpdater.java:107)
at org.eclipse.buildship.core.workspace.internal.ProjectNameUpdater.ensureProjectNameIsFree(ProjectNameUpdater.java:71)
at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildOperation.addNewEclipseProjectToWorkspace(SynchronizeGradleBuildOperation.java:275)
at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildOperation.synchronizeNonWorkspaceProject(SynchronizeGradleBuildOperation.java:259)
at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildOperation.synchronizeGradleProjectWithWorkspaceProject(SynchronizeGradleBuildOperation.java:175)
at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildOperation.access$000(SynchronizeGradleBuildOperation.java:99)
at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildOperation$1.run(SynchronizeGradleBuildOperation.java:134)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2241)
at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2225)
at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildOperation.synchronizeProjectsWithWorkspace(SynchronizeGradleBuildOperation.java:131)
at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildOperation.run(SynchronizeGradleBuildOperation.java:115)
at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildsJob.synchronizeBuild(SynchronizeGradleBuildsJob.java:81)
at org.eclipse.buildship.core.workspace.internal.SynchronizeGradleBuildsJob.runToolingApiJob(SynchronizeGradleBuildsJob.java:72)
at org.eclipse.buildship.core.util.progress.ToolingApiJob$1.run(ToolingApiJob.java:73)
at org.eclipse.buildship.core.util.progress.ToolingApiInvoker.invoke(ToolingApiInvoker.java:62)
at org.eclipse.buildship.core.util.progress.ToolingApiJob.run(ToolingApiJob.java:70)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
My settings.gradle is
rootProject.name = 'mnoxwebserviceendpoints'
include '..:..:mnoxbackendv2:coregeneral',
'..:..:mnoxbackendv2:databasepojos',
'..:..:mnoxbackendv2:backendcommons',
'..:..:mnoxbackendv2:corehttpclient',
'..:..:mnoxbackendv2:corehibernate',
'..:..:mnoxbackendv2:mnoxcache',
'..:..:mnoxbackendv2:coreemailservice',
'..:..:mnoxbackendv2:coresmsservice',
'..:..:mnoxbackendv2:databasecrud',
'..:..:mnoxwebservicesv2:mnoxwebservicescommons',
'..:..:mnoxbackendv2:operationserverendpoints'
My build.gradle has
compile project('..:..:mnoxbackendv2:coregeneral')
compile project('..:..:mnoxbackendv2:databasepojos')
compile project('..:..:mnoxbackendv2:backendcommons')
compile project('..:..:mnoxbackendv2:corehttpclient')
compile project('..:..:mnoxbackendv2:corehibernate')
compile project('..:..:mnoxbackendv2:mnoxcache')
compile project('..:..:mnoxbackendv2:coreemailservice')
compile project('..:..:mnoxbackendv2:coresmsservice')
compile project('..:..:mnoxbackendv2:databasecrud')
compile project('..:..:mnoxwebservicesv2:mnoxwebservicescommons')
compile project('..:..:mnoxbackendv2:operationserverendpoints')
Multi projects are not supported by BuildShip plugin of eclipse. And they have no plans to include this support.
Link to the blog post that confirms this
I will find out which plugin supports eclipse and update this answer.
So I noticed that the "settings.gradle" file was setting the root project name, and after the project rename, it still had the old name. Once I changed that name to the new name and refreshed the project, that error went away.
Actually this error is because of Eclipse,Ideallyeclips should refactor a whole project but it not refactoring settings.gradle file.
there is an issue with your .project file generated by eclipse, delete the project from eclipse(not directory), reopen existing gradle project, rebuild it, issue will resolve.
I have a project in Eclipse for which the Pom file(pom.xml) and Eclipse project file(.project) are not in the same directory. The Pom file is next to the source code.
The project resources in Eclipse are defined as Linked Resources(http://help.eclipse.org/kepler/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Fconcepts%2Fconcepts-13.htm).
I added the pom file as a Linked Resource then and converted the project in Eclipse to a Maven project(Configure -> Convert to Maven Project).
Unfortunately Eclipse is not showing the Maven Dependencies for that project and these are not resolved. Just having the Eclipse project file next to the pom and resources works well for that project but I cannot eventually use it(it's a company rule).
Tanks a lot in advance for your help
Unfortunately Eclipse is not showing the Maven Dependencies for that
project and these are not resolved.
Yeah, and I believe that the Eclipse project files are not going to pick up your changes when you convert to a maven project. This is simply the way maven works because you have the .project file elsewhere.
One note may be helpful: it is generally considered bad practice to check in your .project & .classpath files into src control, no matter where they are located. Can you try and have those files removed from source control and generated for each developer locally.
Personally, I always do that when I first create the Eclipse workspace by creating my project from the pom file: File -> import -> Existing Maven Project and then I browse to the pom.xml file. My understanding is that this is (for many) the preferred way to create the java project in Eclipse.
i just started with java, and created a project.
its maven project (i hadn't use maven yet)
so my project have two modules A and B.
and B depends on A, and A depends on some from remote maven repo. and B also depends on some remote repo.
its works fine in Idea IntelliJ and build jars fine.
but afaik .iml files are Idea IntelliJ specific. and pom.xml is maven specific.
and when i inspect files why all depedecy of project is written in .iml files and .idea dir instead of pom.xml(s)
if you want to see the real world source then here it is but its alpha project for learning java deeply.
and when i try to build project on travis-ci.org it unable to resolve dependencies of project
Meghraj,
I have forked your WebTrimmer repo here : https://github.com/ajorpheus/WebTrimmer and fixed a couple of issues which were preventing a successful build:
The travisci fails because you have three jars in the lib folder which are not available to the CI since it's doing a maven build. The fix was to remove those three jars and introduce corresponding maven dependencies as in this commit.
While adding the maven dependencies an exclusion was needed as noted here : The following artifacts could not be resolved: javax.jms:jms:jar:1.1
The WebTrimmerUI depends on the classes in it's sibling module WebTrimmerEngine, therefore a corresponding dependency is needed.
I have converted the project into a pure maven project which is IDE-agnostic. With the above changes, I can build the project from command line and expect that the travisci should be able to as well.
Regarding the question about why the dependencies are duplicated in .iml --- That's not the reason the CI job fails. The dependencies in that file are a snapshot of the dependencies in the pom.xml. This snapshot is updated when the maven project is re-imported manually by the user, or automatically if the maven project is set to 'Auto-Import'.
As Peter Lawrey mentioned in his comment above, if you add a jar to the project, maven does not know about it and it will be present only in the .iml file.
In general, to search and add a maven dependency, the following has always worked for me: https://stackoverflow.com/a/10178586/325742
Hope this helps !
You need to add dependencies to the pom yourself. The .iml files are for storing project specific settings for whatever project you are currently working on.
Having the pom files allows your maven builds to be IDE independent where as the .iml files require you to have IntelliJ.
You can exclude the .iml files from and version control you are using. You can also open an existing maven project directly via IntelliJ by opening its pom.xml and IntelliJ can auto import everything specified in the pom file and will generate new .iml files.