Fix Maven: Could not find artifact in central


When you add a dependency in your Java Maven projects pom.xml file and try to refresh your project to download the new dependency you may see errors like,

Could not find artifact junit:junit:pom:5.2.1 in central (https://repo.maven.apache.org/maven2)

Reason for the error

  • Invalid or incorrect dependency details.
  • Incorrect artifact version number.
  • Network connectivity issues.
  • A Temporary Outage reaching the repository.
  • Proxy server issues

Example with a fix

Let's say I am trying to add a dependency for Junit with version 5.2.1

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>5.2.1</version>
            <scope>test</scope>
        </dependency>

I get an error here because the version 5.2.1 for junit does not exists at the remote repository: https://repo.maven.apache.org/maven2/junit/junit/

[WARNING] The POM for junit:junit:jar:5.2.1 is missing, no dependency information available
Cannot resolve junit:junit:5.2.1
Unresolved dependency: 'junit:junit:jar:5.2.1'

When I change the dependency version to 4.9 it worked.

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.9</version>
            <scope>test</scope>
        </dependency>

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright ยฉ Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap