could the first ever maven build be made offline?

2020-03-04 08:43发布

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.

3条回答
Juvenile、少年°
2楼-- · 2020-03-04 09:12

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
查看更多
成全新的幸福
3楼-- · 2020-03-04 09:27

You could run maven dependency:go-offline on a brand new .m2 repo for the concerned project. This should download everything that maven needs to be able to run offline. If these are then put into a project-scope local repo, you should be able to achieve what you want. I haven't tried this though

查看更多
等我变得足够好
4楼-- · 2020-03-04 09:29

Specify a local repository location, either within settings.xml file with <localRepository>...</localRepository> or by running mvn with -Dmaven.repo.local=... parameter. After initial project build, all necessary artifacts should be cached locally, and you can reference this repository location the same ways, while running other Maven builds in offline mode (mvn -o ...).

查看更多
登录 后发表回答