GIVEN:
I have an in house tool built with gradle that includes a dependency that is only a POM file which in turn then includes a bunch of other dependencies. No jar for this particular dependency by itself. The tool builds.
I have a maven project with a pom.xml file that I want to include this tool in because of all the company specific methods needed for some processes. I added the dependency with the type of pom and when I build it fails.
ERROR:
[ERROR] Failed to execute goal on project <MYPROJECT>: Could not resolve dependencies for project <MYPROJECT>:jar:0.0.326: <com.pom.only.dependency>:jar:7.0 was not found in <Company Repo where this POM file exists> during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of <company repo> has elapsed or updates are forced
REQUEST:
I have tried making the tool a fat jar in the hopes it would not need this. But it does. The my project builds without this tool jar so I know it is this jar that brings in the dependency. I just have no idea how to resolve this.
ALMOST CODE EXAMPLE
Because of company specific, I can not put the exact POM code but I can put what it looks like removing company specific stuff.
<dependency>
<groupId>com.group</groupId>
<artifactId>tools-app</artifactId>
<version>1.0.11</version>
</dependency>
<dependency>
<groupId>com.group</groupId>
<artifactId>pom only dependency</artifactId>
<version>7.0</version>
<type>pom</type>
</dependency>
So tools app is the one that I am pulling it. It is the gradle build and uses the pom only dependency without any issue. If I pull this into a gradle app it works fine and builds. However, in the app that has this in the pom, if fails for above. So I add the dependency for the pom only dependency and mark it as type pom but still get the error.
So for my situation (and not the best solution), I went into the dependency that has only a pom and pulled the dependencies out of there and built. It worked. But feel there should be a way to make it work without having to do this.
I am following this tutorial. Also, on my local machine I have two Maven projects; let's call them:
MyAppDAO (contains all database related code),
MyAppWorker (performs the background tasks on the database).
The relationship between the two is that MyAppWorker includes MyAppDAO as a Maven dependency so that it can work with the database; in the pom.xml of MyAppWorker I have
<dependencies>
...
<dependency>
<groupId>com.someone.myapp</groupId>
<artifactId>MyAppDAO</artifactId>
<version>1.0</version>
</dependency>
...
</dependencies>
I was able to make it work locally, yet whenever I try to push MyAppWorker to Heroku, I get:
[ERROR] Failed to execute goal on project MyAppWorker: Could not resolve dependencies for project com.someone.myapp:MyAppWorker:jar:1.0: Could not find artifact com.someone:MyAppDAO:jar:1.0 in central (https://repo.maven.apache.org/maven2) -> [Help 1]
My best guess is that I have to tell Maven not to search MyAppDAO at https://repo.maven.apache.org/maven2 but to look at the <project_folder>/target/dependency, yet I did not find any helpful information on how to resolve the issue assuming my guess is correct in the first place.
Following these instructions solved my problem.
This error won't go away even after many 'mvn clean install' and reimport pom.xml's
[ERROR] Failed to execute goal on project foo:
Could not resolve dependencies for project be.foo:foo:jar:2.0-SNAPSHOT:
The following artifacts could not be resolved:
org.neo4j:neo4j-spatial:jar:0.12-neo4j-2.0.4,
diff_match_patch:diff_match_patch:jar:current:
Failure to find org.neo4j:neo4j-spatial:jar:0.12-neo4j-2.0.4 in
https://repo.spring.io/libs-release was cached in the local repository,
resolution will not be reattempted until the update interval of spring-releases has elapsed or updates are forced -> [Help 1]
eventhough the pom clearly has the dependency:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-spatial</artifactId>
<version>0.12-neo4j-2.0.4</version>
</dependency>
Weirdest thing is I don't even think I need this in my project, it just started complaining about it.
So far I'm guessing that it has to do with some sort of version mismatch?
"diff_match_patch" etc
If you go to the URL thart´s shown in your logs, you´ll see that library is not there. You probably need to change the version or set up a different repo.
I am new to programming web applications, and so far I am working with a eclipse/maven-setup with a Jetty server, to develop java web-apps.
One thing I do not understand however, is the dynamics of including external jars. Many tutorials, and Q&A's here on SO claims that it is enough to add the jar to WEB-INF/lib. other explain how I need to add them as dependencies in pom.xml. I have found that some times the first solution works, while some times I also need to add the dependency. I am not sure why it is this way. In addition, when adding dependencies, I have manually copied the external .jars to folders matching the already excisting repository resources. I can't believe that this is the right way to do it, but it has been working out for me.
So my questions are:
Am I correct that the jars need to be double referenced, or am I making a work around for a possible other problem?
What is the difference between the two methods of import/referral?
Bonus Question: Why are the errors below showing up in eclipse? These refers to all of the jars I have tagged as dependencies in pom.xml. The web-app runs as it should, although with seemingly random different runtime errors after a period of time. Restart of the server fixes it at the moment.
Description Resource Path Location Type
Missing artifact standard:standard:jar:1.1.2 pom.xml /WebApp line 1 Maven Dependency Problem
Missing artifact jstl:jstl:jar:1.2 pom.xml /WebApp line 1 Maven Dependency Problem
Missing artifact junit:junit:jar:4.8.2 pom.xml /WebApp line 1 Maven Dependency Problem
ArtifactDescriptorException: Failed to read artifact descriptor for javax.servlet:javaee-web-api:jar:6.0: ArtifactResolutionException: Failure to transfer javax.servlet:javaee-web-api:pom:6.0 from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact javax.servlet:javaee-web-api:pom:6.0 from/to central (http://repo.maven.apache.org/maven2): connection timed out to http://repo.maven.apache.org/maven2/javax/servlet/javaee-web-api/6.0/javaee-web-api-6.0.pom pom.xml /WebApp line 1 Maven Dependency Problem
Missing artifact com4j:com4j:jar:1.0 pom.xml /WebApp line 1 Maven Dependency Problem
WebApp Unknown Validation Message
WebApp Unknown Validation Message
WebApp Unknown Validation Message
(Yes there is a total of 8 errors, whereof 3 is completely empty in eclipse.
There is not any difference at all. Maven's pom.xml helps to download all jar files at .m2/repository location. These jars can be used for different projects. You need not to manually download. But for the very first time you need internet connection to download all jar files.
In pom.xml we have to set dependencies like given below or whatever version of jars you want to download. If later point in time you want to change the version ( in following case ${spring.version} then you have to change only one place and everywhere get reflected.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
If you don't use pom.xml then while transfering project you will have to transfer all jar files over the network many times.
Maven give re-usability of jar files in multiple project. You need not to have deep copy of all jar files in WEB-INF/lib folder.
EDIT 1
In very first attempt, any project will download all jar files from internet and will store all those jar files at .m2/repository. Second time in another project, when you try to use other pom.xml file then maven will try to find jars at local (your computer) .m2/repository whatever dependencies defined in your new project's pom.xml if those files are there in .m2/repository then maven will not try to connect to internet to download (because everything is downloaded at .m2/repository).
If pom.xml file finds new entry then it will connect to internet and then download at .m2/repository
EDIT 2
Maven first checks dependency at local repository (.m2/repository), if not found then maven central repository (needs internet connection) and even if maven is not able to find at central repository then we have to tell those thing into the pom.xml file to download it from some other location.
For Ex.
<repositories>
<repository>
<id>java.net</id>
<url>https://maven.java.net/content/repositories/public/</url>
</repository>
</repositories>
maven is a build tool, which also manages your project dependencies. It helps you build your project outside Eclipse as well. You should either use maven or directly manage your project dependencies in (or outside) Eclipse on your own. In the latter case, possibly you don't need maven.
As for the bonus question, looks like there are some connection issues which is resulting in artifacts not getting downloaded (connection timed out) - maybe your system is behind a proxy server.
When I open a POM file and click on the "Dependency Hierarchy" tab at the bottom, it gives me the error, "Project read error". It works with other projects in the same workspace, just not with this one. Any ideas?
EDIT
In response to #Yhn's answer.
Running the compile and package phases outside of Eclipse from the command-line work as expected. It compiles the application and builds the final WAR file.
Eclipse is indeed pointing to the default location of the Maven settings.xml file, so it should be aware of the custom repositories that are defined in it (my company has its own Maven repository).
I can open and edit the POM file from Eclipse, so it must have read/write permissions to the file.
The project is not configured in Eclipse as a Maven project, so I cannot run the package phase from Eclipse (I can only run it from the command-line).
I wonder if it has anything to do with the fact that I was having trouble building the project with Maven 3 because apparently some of the transitive dependencies are configured for Maven 1, which Maven 3 does not support (this is my theory anyway, based on some of the error messages). I can build the project with Maven 2, but I still get messages such as the following:
Downloading: http://dist.codehaus.org/mule/dependencies/maven2/org/codehaus/xfie/bcprov-jdk14/133/bcprov-jdk14-133.pom
[INFO] Unable to find resource 'org.codehaus.xfire:bcprov-jdk14:pom:133' in repsitory mule (http://dist.codehaus.org/mule/dependencies/maven2)
It must be able to find these dependences however, because it downloaded the JARs just fine and can build the application. It seems like the problem is that the dependencies don't have POM files associated with them, which is maybe why they cannot be used with Maven 3. This might also be why I cannot view the Dependency Hierarchy in Eclipse.
EDIT 2
I converted the project to a Maven project by going to "Configure > Convert to Maven Project". When I open the POM file, I see the error:
ArtifactDescriptorException: Failed to read artifact descriptor for woodstox:wst (Click for 140 more)
(woodstox:wst is another transitive dependency of the project). An error appears in the "Markers" view for seemingly every depedency and transitive dependency in my project. However, I can successfully build the project by doing a "Run As > Maven build". (Edit: This might be because this project has no Java source code, but the JARs of the dependencies correctly appear in the final WAR.) The Dependency Hierarchy still gives the same error--"Project read error".
About the "Unable to find resource" messages--but this only appears for a handful of transitive dependencies. The project has many more transitive dependencies, but these messages do not appear for them. It seems like, because the dependencies do not have POM files, that Maven tries to search for them every time the project is built. Is this normal not to have POMs??
How might I go about getting a repo manager? Is this something that would have to be installed on the company's Maven repository or can you install it on your own workstation?
I had this problem with some non-maven jars that I needed to include in my maven project. I put the jars in my local repository using this maven command:
mvn install:install-file -Dfile=/test/gov.nist.xccdf-1.2.jar -DgroupId=gov.nist -DartifactId=xccdf -Dpackaging=jar -Dversion=1.2
Then I referred to them as dependencies in my pom.xml:
<dependency>
<groupId>gov.nist</groupId>
<artifactId>xccdf</artifactId>
<version>1.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
This worked fine for a while, but I must have upgraded something in eclipse, and I started getting the error you describe.
The fix is to take them out of the local repository, and redo the install-file asking maven to generate a pom for you:
mvn -DgeneratePom=true install:install-file -Dfile=/test/gov.nist.xccdf-1.2.jar -DgroupId=gov.nist -DartifactId=xccdf -Dpackaging=jar -Dversion=1.2
The command will cause a pom to be generated in the same directory (within your local repo) where the jar is placed.
In recent versions of eclipse maven support, the maven build is still done with maven 2 (if you right-click your pom.xml, choose run as mvn package for example). The dependency analysis is now done with an embedded maven 3 plugin, which doesn't like a dependency that has no pom.xml.
I had the same problem. If you made your project a maven project, you should run:
Right Mouse Click on project | Maven | Update Dependencies or
Right Mouse Click on project | Maven | Update Project Configuration
That worked for me.
Given the information through the comments:
mvn compile/mvn package work through console (I'm assuming outside of eclipse). Based on that, the POM file should be correct and dependencies can be resolved.
However; it could be that eclipse's settings aren't correct. For example, if eclipse has some own maven properties (instead of the default ~/.m2/settings.xml file); I can imagine it to fail resolving dependencies configured in the settings.xml used by maven itself. The settings for this should be in the Eclipse Preferences # Maven > User Settings.
Also make sure that Eclipse can actually read the file (not locked, correct rights, etc).
Should this seem to be correct; can you try to run the mvn goal compile from eclipse? You can do this by right-clicking the project and selecting run as > maven package. That way it should run maven with the same settings as eclipse is using, and might show any additional errors in it's configuration.
--
In response to additional information:
Basically it tells you - when using Maven 2 - that it can't find a dependency resource (in this case bcprov-jdk14) in the given repository (codehaus/mule). When I search that maven module (bcprov-jdk14) I find it in the Maven central repo (through our local nexus) # repo1.maven.org/maven2. Maybe that causes the error you're getting with Maven2?
And as the Maven 3 doc says; for Maven 1.x repo's; you should proxy them through a repo manager that can serve it to you as a maven 2 repository (I believe we do that here too for some repo's through Sonatype Nexus OSS)
ps.: Enabling maven dependency management in eclipse should be enough to be able to use maven run targets; if you would want to test it.
--
Sound like it can be multiple problems... given that the normal maven build works fine, one would think that maven can at least get the artifacts it depends upon and their dependencies... Yet, eclipse doesn't seem to be able to.
Double check if your Eclipse internet connection settings are correct? Since you were talking about a company repo, I'm assuming there will probably also be a proxy (I had to set up my Eclipse to use that one too; though for plugins (see next point)).
Another possibility, from experience, can be a rule-based proxy block on *.pom url requests (our proxy here blocks that to force usage of the local repo manager, how evil and annoying that is :(). You might want to try and open the .pom file it tries to download manually in your browser to see if this is the case (I can't, for example...).
To get the repo set up, you would probably have to ask the one responsible for the repository to add it as a maven2 proxy.
At the very least, it seems Eclipse is having issues getting the dependency poms (which are needed to build the dependency tree) from the internet. You could always try to ask some ICT crew (if they are capable enough...) about it at your company, maybe they have some useful hints.
right click on the project, Maven->Update Project->Tick "Force Update of Snapshots/Releases"
I had the same problem when I added a new dependency to pom.xml without network connection. After this, I had so many problems such as "Missing artifacts", "Missing Descriptor", or "Project Read error". I solved this
delete the bad dependency just added from local repository.
rebuild local index.
re-add the dependency
<properties>
<!-- ********************** -->
<!-- Plugin's properties -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.7</java.version>
</properties>
this pom setting worked for me
Usually this happens if there is a typo in the pom that Maven cannot understand and then it throws Project read error. Like in my case I copied a maven dependency snippet and I by passed the version. Instead of typing the actual version # it was getting it dynamically ${asciidoctorj.version} and my pom didn't have this in the properties section. So I got this error. Once I removed that and put a version number it started working.
I had this after copying a local repository folder from another machine. The fix was to go into the repository folder I copied and delete
_remote.repositories along with the 'LastUpdated' files then refresh the Maven dependencies in Eclipse (Alt+F5)
I faced same situation today. In my case it's caused by dependency name in wrong case. E.g.
Project A -> Project B -> Project C
In project B's pm file, I mistakenly specified the dependency artifacts name with "c" in stead of "C".
As in mac os, the files system is case insensitive. so I can build it in command line without detecting this mistake.
In Eclipse it breaks, but it provides very bad error message. In the error list, it says "dependency problem", but the name of dependency is empty. It also can't identify which line in the POM causes the problem.
When try to open "Effective POM" in POM viewer, it will show project read error. In the pop up error dialog box, it will show:
Could not read maven project
java.nio.channels.OverlappingFileLockException
All the messages are useless and misleading.
I finally detected this problem by submit to Jenkins CI after wasted hours of time.
I did maven clean install and the errors were gone
I faced the same issue of "Project read error" while clicking on "Dependency Hierarchy" tab. In my project I had a parent pom and child pom.
Parent pom had a property <appVersion>4.5<appVersion> that was being used in child pom
<version>${appVersion}<version>.
I selected the main project, right click and choose run as maven clean. The console display showed warning that version is using expression but should be a constant. Replacing ${appVersion} with constant value of 4.5 fixed the issue.