Maven Resolve Missing Artifact Error Example
In this example, we will be discussing about how to resolve “Missing Artifact” error while using Maven. Before we start with this article, it is expected that we have a basic understanding of how software development works with Java. It would also be good if we have an exposure to software build and deployment process to understand the usage and the working of the Apache Maven better. To get familiar with the installation, the usage and the basics of Maven please refer to the article Maven Hello World.
In this example, we will see how to resolve “Missing artifact error” while working with Maven.
1. Introduction
In general software terms, an artifact
is something produced by the software development process, whether it is software related documentation or an executable file.
In Maven terminology, an artifact
is a file, usually a JAR
, that gets deployed to a Maven repository. It is a resource generated by a maven project. Each maven project can have exactly one artifact
like a jar, war, ear
, etc. Each artifact
has a group ID (usually a reversed domain name, like com.jcg.maven), an artifact ID (just a name), and a version string. The three together uniquely identify the artifact. You can refer to the pom.xml
below.
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.jcg.maven</groupId> <artifactId>MavenHelloWorldProject</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>MavenHelloWorldProject</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>
2. Missing Artifact error
Maven artifacts are not limited to java resources. We can generate whatever resource we need like, documentation, project-site, zip-archives, native-libraries, etc.
Each maven project has a unique identifier consisting of [groupId, artifactId, version]
. When a maven project requires resources of another project a dependency is configured in it’s pom.xml
using the [groupId, artifactId, version]
identifier. Maven then automatically resolves the dependencies when a build is triggered. The artifacts of the required projects are then loaded either from the local repository
, which is a simple directory in user’s home, or from other (remote) repositories specified in the projects pom.xml
.
Maven throws “Missing artifact error” when a dependency is not recognized or a dependency artifact cannot be found either in the local repository or the remote repository depending on how we have configured our project to get the dependencies (check the <url>
tag in pom.xml which helps to determine where maven will refer the dependencies). It may also means that Maven is not able to download the artifacts specified in the pom.xml
from the repository.
3. Resolving Missing Artifact error
Whenever we get a missing artifact error while building our Maven project, the only thing we should first try out is to check for dependencies in the pom.xml
.
Things that can be checked in pom.xml
:
- Check if the correct repository is specified in the
pom.xml
from which the package was downloaded originally. It might happen that the url inpom.xml
is not correct and you have the required jar file in the .m2 repository. - Check for the artifact version, if the version specified in the
pom.xml
is there in the repository from where it should be downloaded. - Check if the jar is missing or not. If yes, place it manually in the .m2 repository. Sometimes the jar mentioned in the
pom.xml
is not downloaded and it gives error. - You can also try deleting the entire .m2 repository folder and run the maven build. The jars get downloaded from scratch. It might resolve the problem as well.
- In eclipse, you can always try to clean the project by selecting the Project->Clean option. There are a few other options apart from Project->Clean, some of which are more along the lines of turning it off and on again.
- Try right-clicking on the project and select Maven->Update Project.
- Disable then re-enable dependency management (right-click Maven->Disable Maven Nature then to again convert the project to a Maven project, Right Click on the project and select Configure ->Convert To Maven Project. Please refer to the screen shots below.
- Close the project and reopen it.
6. Check that your Maven settings are configured correctly. If you are behind a proxy you’ll need to configure the proxy settings in the global or user settings.
7. You can also try right-clicking on the project and select Maven -> Update Project and check the option for “Force Update of Snapshot/Releases”. It will clean build the project checking for dependencies. Refer to the screenshot below.
4. Conclusion
That was an example of the “Missing Artifact error” while building a Maven project. We saw some things that can be checked in order to resolve this error.
In my case I had to add the repository
maven-restlet
Restlet repository
https://maven.restlet.com
Great! Problem resolved!
problem not solved :(
when i tried to update Maven project it says Multiple Problem occurred . Problem not solved
Excellent you solved my problem which I’m struggling from last few days