Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

could the first ever maven build be made offline?

The problem: you have a zipped java project distribution, which depends on several libraries like spring-core, spring-context, jacskon, testng and slf4j. The task is to make the thing buildable offline. It's okay to create project-scope local repo with all required library jars.

I've tried to do that. Looks like even as the project contains the jars it requires for javac and runtime, the build would still require internet access. Maven would still lurk into network to fetch most of its own plugins it requires for the build. I assume that maven is run with empty .m2 directory (as this may be the first launch of the build, which may be an offline build). No, I am not okay with distributing full maven repo snapshot along the project itself, as this looks like an utter mess for me.

A bit of backround: the broader task is to create windows portable-style JDK/IntelliJ Idea distribution which goes along the project and allows for some minimal java coding/running inside IDE with minimal configuration and minimal internet access. The project is targeted towards students in a computer class, with little or no control over system configuration. It is desirable to keep console build system intact for the offline mode, but I guess that maven is overly dependent on the network, so I have to ditch it in favor of good old ant.

So, what's your opinion, could we move first maven build in offline mode completely? My gut feeling is that initial maven distribution just contains the bare minimum required to pull essential plugins off the main repo and is not fully functional without seeing the main repo at least once.

like image 972
Anton Kraievyi Avatar asked Feb 04 '26 04:02

Anton Kraievyi


1 Answers

Maven has a '-o' switch which allows you to build offline:

 -o,--offline                           Work offline

Of course, you will need to have your dependencies already cached into your $HOME/.m2/repository for this to build without errors. You can load the dependencies with:

mvn dependency:go-offline

I tried this process and it doesn't seem to fully work. I did a:

rm -rf $HOME/.m2/repository
mvn dependency:go-offline       # lot of stuff downloaded
# unplugged my network
# develop stuff
mvn install                     # errors from missing plugins

What did work however is:

rm -rf $HOME/.m2/repository
mvn install                     # while still online
# unplugged my network
# develop stuff
mvn install
like image 138
Gray Avatar answered Feb 05 '26 21:02

Gray



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!