Is there a maven command line option for offline mode?

前端 未结 5 975
天命终不由人
天命终不由人 2020-12-23 19:02

You can specify in your maven settings file that you want to run in offline mode, but is there an equivalent command line option?

I would imagine something like e.g

相关标签:
5条回答
  • 2020-12-23 19:02

    Maven's offline mode is invoked using mvn -o.

    However, that alone may not be enough, because sometimes the current project refers to artifacts which are not yet present in the Maven local repository cache (~/.m2/repository). Attempting to build that project in offline mode will fail, because needed dependencies are missing and cannot be downloaded.

    So there is another useful goal:

    mvn dependency:go-offline
    

    This is a great command to run before hopping on a plane, which will improve your chances of BUILD SUCCESS. See the go-offline documentation for details.

    0 讨论(0)
  • 2020-12-23 19:03

    Just a simple:

    mvn --offline
    

    In the future, I recommend referring to mvn --help.

    0 讨论(0)
  • 2020-12-23 19:04

    mvn -o works in most of cases but in some cases it will not enough as from Maven 3 a downloaded artifact from a remote/central repository creates a _remote.repositories file in your local repository with a reference about where the dependency was downloaded.
    It may causes some issues if later you don't have access to this remote repository during your builds.
    A workaround that may work is using mvn -o -llr yourGoal.

    From the help documentation :

     -llr,--legacy-local-repository         Use Maven 2 Legacy Local
                                            Repository behaviour, ie no use of
                                            _remote.repositories. Can also be
                                            activated by using
                                            -Dmaven.legacyLocalRepo=true
    
     -o,--offline                           Work offline
    

    Another way to execute mvn in an offline way is deleting these _remote.repositories meta data stored in the directory of the downloaded dependencies.

    0 讨论(0)
  • 2020-12-23 19:11

    Specify offline mode via -o/--offline:

    mvn -o install
    

    Maven book reference

    0 讨论(0)
  • 2020-12-23 19:22

    Try -o, or even --help to get help with all options

    0 讨论(0)
提交回复
热议问题