16

Problem:

I have a maven project that builds & compiles fine using maven tool from command-line.

Then I have IntelliJ IDEA that refuses to build said project, claiming that some of dependencies are not available.

I've found out that the root of the problem is in fact that IntelliJ can't connect to maven repositories which contain said dependencies. Of repositories, there are 3:

  1. apache's maven repo (https://repo.maven.apache.org/maven2)

  2. sonatype's oss repo (https://oss.sonatype.org/content/repositories/snapshots)

  3. company's internal repo (url omitted)

All three are available, accessible through browser for viewing, and dependencies from them are fetched using maven command line interface.

But, IntelliJ just says ".. can't reconnect" and shows errors about updating said repos. I've tried to use different maven options (my local installation, 3.5.2; intellij's bundled maven2 and maven3), to no avail yet.

Any idea why that could happened?

EricSchaefer
  • 25,272
  • 21
  • 67
  • 103
Mikhail Krutov
  • 670
  • 1
  • 5
  • 29
  • 1
    have you checked your settings.xml file? – Stultuske Feb 20 '18 at 13:17
  • 1
    I didn't change anything there, and just removed ~/.m2 repo to be re-downloaded by mvn while building by-hand, so it should be all default. Looking into it now. Upd: yes, settings.xml just doesnt exist in ~/.m2 so all should be maven's defaults. Its not set to be overriden in IDEA as well. – Mikhail Krutov Feb 20 '18 at 13:23
  • The apache repo and sonatype snapshots are not used by default only Maven Central...nothing else if you don't have a settings.xml file... – khmarbaise Feb 20 '18 at 13:55
  • repositories are declared in my `pom.xml` instead, not in settings.xml – Mikhail Krutov Feb 20 '18 at 14:33
  • @MikhailKrutov Does your project build from the command line Maven? See also http://stackoverflow.com/a/42427510/104891. – CrazyCoder Feb 20 '18 at 19:19
  • 1
    Are you behind a proxy...? – Software Engineer Mar 11 '21 at 22:10
  • Have you tried quitting IntelliJ and rebooting the computer? Have you tried [clearing caches](https://www.jetbrains.com/help/idea/invalidate-caches.html) and restarting? What version of IntelliJ are you using? Have you tried updating to a later version of IntelliJ? For some other oddball things to try, see [this similar Question](https://stackoverflow.com/q/45365878/642706). – Basil Bourque Mar 12 '21 at 03:05

2 Answers2

1

First, if you work in a big company/corporation, there's a good chance you're using a proxy, be sure to ask your coworkers about configuring your connection. Also, there is probably some Artifactory/Nexus repository in use, which also needs to be configured to allow dependencies to be downloaded. All of this information should be included in the settings.xml file, which should be in the Maven settings (or other build tool, but I only used Maven).

The other thing is that there are problems with the Maven bundled into Intellij. I tried configuring it in many ways inside the IDE, but unfortunately nothing helped, even though the settings.xml file was in the .m2 folder.

I installed a standalone Maven where I put the settings.xml file in the /conf folder. Then just point to the Maven location inside the IDE, preferably delete the contents of the .m2 folder (this will remove both the local settings and the downloaded dependencies) and everything should work fine.

Also remember about VPN connection - sometimes downloading artifacts from repositories is only possible through it.

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
bartoni
  • 51
  • 3
0

I have run into this many times also and the only solution that has worked is to restart IntelliJ which has worked every time.

Michael Peterson
  • 10,383
  • 3
  • 54
  • 51