开发者

m2eclipse says "Missing artifact" but I can build from cmdline!

开发者 https://www.devze.com 2023-02-20 20:17 出处:网络
I\'m trying to use this Sonatype Eclipse plugin for the first time to handle an existing (huge) software that I can build with maven form the command line.

I'm trying to use this Sonatype Eclipse plugin for the first time to handle an existing (huge) software that I can build with maven form the command line.

I have configured the plugin to use my maven 2.2.1 installation instead of the built-in Maven 3.

In Eclipse I have 25 projects (loaded through the root pom.xml) and 4 of them have compilation errors; the maven console contains a lot of lines like this one:

Missing artifact commons-logging:commons-logging:jar:1.0.4:compile

I have all the jars in my reposito开发者_C百科ry and the M2_REPO classpath variable correctly defined. Why the plugin doesn't see all the jars?

The .classpath file of those projects simply references "MAVEN2_CLASSPATH_CONTAINER", there isn't a list of the jars. The pom.xml in Eclipse shows an error on the first line for the missing jars but I can build from the command line!

Any idea? I need help! I will try to move to NetBeans if I don't solve this problem.

Thank you.


You may need to to tell Eclipse to force update:

Project -> Maven -> Update Maven Project

and then make sure you have selected:

Force Updates of Snapshots/Releases

this happens when mvn install copies some jar files into Maven repository and Eclipse had checked this repo BEFORE this jar has been copied there.


If Dependency management is enabled when the above problems occur in Eclipse you can Project > Maven > Disable Dependency Management and then \Project > Maven > Enable Dependency Management. This normally remove any dependency errors in the pom.xml.

Also do as @Nishant indicated in his answer above after the above steps to complete the projects dependencies.


right click on your project > Maven > Update Dependencies

then

right click on your project > Maven > Update Project configuration

Assuming you M2Eclipse plugin is installed correctly this should solve the issue. Also, check if there is an option right click project > Maven > Enable dependency Management select that.


Using Eclipse Kepler, the removing and re-adding of the maven nature fixed this same issue I was having. What this process actually did was modify the .settings/org.eclipse.m2e.core.prefs file, changing the line

resolveWorkspaceProjects=false

to

resolveWorkspaceProjects=true

So you could probably make this change manually if you had to.


Adding my 2c for future Googlers:

Whenever this problem shows up, I delete the corresponding folder from the m2 repository (on a mac it's on ~/.m2/repository) and build again from eclipse with clean install.

Works every single time.


Close eclipse IDE and open it again, this issue should be fixed.


Just to add yet another possible resolution, if you have a multi-project build with interdependencies, if you have a repository defined in a child project pom to resolve a specific dependency that only that project depends on and it is relying on a partent project for it's other resolutions it fails to see those dependencies in the child project (even though it works from the command line).

Move the repo definition to the parent pom.


The lack of jars in the build path suggests you haven't enabled Maven dependencies. Right-click on the project, select Maven, select "Enable Maven Dependency Management". This allows M2Eclipse to reference your POM.


I finally found a workaround. It is surely a bug in m2eclipse, however the problem disappeared when I added quartz-1.6.0.pom next to quartz-1.6.0.jar in .m2\repository\opensymphony\quartz\1.6.0\
The pom is not present at http://repo1.maven.org/maven2/opensymphony/quartz/1.6.0/ but you can extract it from quartz-1.6.0-bundle.jar linket at http://jira.opensymphony.com/browse/QUARTZ-482
It's a strange solution but it worked on the PCs of my collegues too.


None of the other suggestions worked, but the following steps worked for me (SpringSource Tool Suite 2.6.1):

  • Back up the contents of the local Maven repository
  • Delete the repository
  • Project > Maven > Update Dependencies
  • Replace anything not available in a public repository from the backup


If disabling and enabling project dependency management doesn't help (usualy it helps) you can modify .classpath file in your project and add a line:

<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>

After eclipse restart dependencies should be added.


I had this same problem happened to me. On the CLI clean install, then on eclipse delete the dependency, paste it again and that did the trick.


Remove all the artifacts except the jar in maven local repository


Late answer: In my case I had multiple profiles in settings.xml. Building worked since the correct profile was selected in the Maven Build run config, but the editors showed errors because the profile was not selected via Project -> Maven -> Select Maven Profiles ...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号