Gotcha when reimporting Maven dependencies from IntelliJ with missing permissions to remote maven feed

tl;dr
It looks like IntelliJ Maven support while reimporting dependencies do not care for any authentication errors at all. If it tries to fetch a dependency that it could not find, it looks like it just create a near empt directory in $HOME/.m2/repositories.

Today I made a change to a library that I pushed to the Azure DevOps repository and the build pipeline kicked off. A new snapshop dependency was created and pushed to the maven artifact feed in Azure DevOps. I then went back to the project where I wanted to use my newly made changes and off course I needed to reimport the snapshot dependency to get the newly created version. Since I am using IntellJ, I just right-clicked at the pom.xml file and in the Maven context menu, there is an option to reimport. Normally this is working fine. After I did this, there was no change at all for me. To check this out, I went to $HOME/.m2/repositoryand browsed the dependency there. Still the old version. Then I deleted the folder so I could make a reimport again and now I had all sorts of errors and missing objects all from that dependency. The folder for the dependency was present in the maven cache on disk.

Do what should I do now? The reimport functionality normally works fine, but I then thought that I should try to run maven from the command line instead by the following command: mvn clean install -U. This time, I could see that it tried to find the dependency missing from the maven feed in Azure DevOps, but just got 401 UnAuthorized. Now I did not understand anything, IntelliJ did not say anything about a 401 error message and the dependency was present. I then looked into the dependency folder and there I could see a near empty folder. No jar files at all.

Since I now probably do not have access to the Maven repository, I could go into Azure DevOps and check my personal access token and there I could see, that token did no longer have readaccess at the packaging part. After I checked out that it should have access to packaging with read access, I was able to run the maven command from command line and from IntalliJ itself.

Teis Lindemark

Read more posts by this author.