- Creating a custom spaCy tokenizer to use with Prodigy - 22. September 2021
- Troubleshooting H2 Database in Spring Boot - 6. März 2020
- Intercept Callable execution with ExecutorService in Java - 25. November 2019
Maven is all about connectivity. It allows you to quickly specify a dependency in the pom.xml file and forget about it. Maven will handle it for you. It will download it when necessary. If the dependency is already downloaded, it only connects to the remote repository for synchronization purposes.
However, in some cases you need to work offline. You need to tell maven to stop trying to synchronize or download the required dependencies.
Since you still need the dependencies, this implies a two step process: Download required dependencies & Actually execute the required goal.
In my case, I needed to download all the needed dependencies in the local repository up-front and later on to execute the install goal on the maven project.
To download all the dependencies up-front maven offers “dependency:go-offline” goal. You need to execute this goal on your project (i.e.: navigate to project folder and then ‘mvn dependency:go-offline’)
Once you run this, you’ll see how to required dependencies are downloaded. Now they are all stored in your local repository
As mentioned, even if you have all the dependencies in the local repository, maven will still go to the network and check if everything is up-to-date.
We need to instruct maven that we don’t need to use the network and we need to work offline.
This is done with the help of a flag passed to mvn command: -o, -offline
Documentation for the command line flags can be found here: https://maven.apache.org/ref/3.1.0/maven-embedder/cli.html
As an example for the install goal, you would do: mvn -o install
More to the story
My use case involved switching between maven repository dynamically. To have a clean state for maven, the content of ~/.m2/repository was emptied so that after switching to new repository it will download fresh the artifacts it needs.
This state of affairs brought some issues to itself.
Namely, if you empty the entire repository folder, it means you will be discarding also the required dependencies of the default maven plugins ( plus eventual dynamic dependencies inside the plugins).
These dependencies are not downloaded by the dependency:go-offline goal. It works only for dependencies used directly by the project itself.
The solution in my case was to simply run all the goals before install goal: clean, resources, compile, test