Friday, May 25, 2012

Using Maven Offline

Here's another micro blog intended to help other programmers avoid a very frustrating day of trying to get Maven to work offline. I've only been using Maven for a few months, and today was the first day I worked from home, away from the office, on a new Maven project. I had my laptop with me and assumed I could just tell Maven to work offline out of my local repository. Sounds simple right? I have all the jars I need right here on my local machine. Well, what should have been straight forward was a nightmare, which in the end is very silly and Maven COULD have made this much easier to debug. Hopefully in the next release they will consider improving their error messages.

Version Information

Maven 3.0.4

The Problem

To run Maven offline, you need to use the -o argument or set offline to true in settings.xml. I assumed that would be all that's necessary, but I kept getting the following errors for third-party jars that I added to our Nexus repo at work:

Failure to find blah in 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 -> [Help 1]

Failed to execute goal on project blah : Could not resolve dependencies for project

The following artifacts could not be resolved

[WARNING] The POM for blah is missing, no dependency information available

The repository system is offline but the artifact blah is not available in the local repository.

The Reason

After an entire day of tracking down the problem online, I finally stumbled upon the reason for all the issues described in these three articles.

One
Two
Three

To quote the first one:

"Thank you. That was the problem. I had had a setting.xml that pointed to
an internal repo at my company, and then cleared it out. Maven puts a
file named _maven.repositories in with the jar file in the local repo
that keeps track of where the jar came from. If the remote repo isn't
available, the build fails. Deleting _maven.repositories solved the
problem.

This seems like an extrordinarily bad design. If a remote system goes
down, you can't do a build? If you have an internal repo at work, and
you take your laptop home, you can't do a build?"

The Solution

Delete all _maven.repositories files in your local repository. Once I did that, the build worked like it should. There's arguably a good reason for Maven to use these files, but it's pretty weak that Maven couldn't improve the error message for this situation. Please go to the Jira Issue Page for this and upvote this.

10 comments:

Anonymous said...

Thank you, it worked.

rado said...

Thanks, I had the same problem

Unknown said...

You just saved me another 3 hours of pain on the train. Thank you!

Anonymous said...

Thank you very much :)

Anonymous said...

Thanks a lot!

Unknown said...

Thank you!

Unknown said...

you saved my time. Thank you!

Anonymous said...

How silly! Thank you so much for writing about he solution.

Anonymous said...

Thanks, that did the trick!)

flange said...

Dear all,
Developpers want to use sonars.

Is-it possible to create all the needed Oracle Objects ( tables, indexes, sequences, ... ) in a user "sonar_object_owner" and grant the access and create synonyms for the user "SonarQube Runner" and "SonarServer".
Nobody is allow to connect with DDL grants in our organization.

Regard F rançois L ange