Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing local repository in offline mode

Tags:

maven

maven-3

I need to make Maven access local repository (file://) when it is ran in offline mode (basically, I am trying to setup repository hierarchy so it does not put artifacts where I don't need them).

This does not work out-of-the-box, though I always assumed this scenario is supported. Is there some flag to enable particular repository in offline mode?

like image 223
Eugene Avatar asked Mar 06 '12 00:03

Eugene


2 Answers

For the dev environment only, if you use IntelliJ IDEA, you can configure Maven to work offline as follow:

Preferences... > Search for Maven > Work offline (checked)
like image 125
Alex B Avatar answered Sep 18 '22 12:09

Alex B


It is possible to set up profiles for repositories utilizing the local file system rather than a network address.

<repository>
   <id>mymaven</id>
   <url>file://D:\mylocalrepo</url>
</repository>

According to documentation, it is also possible to reference offline mode in a property value.

${settings.offline}

You would then leverage these together to activate a given settings profile according to the examples here. (If Maven doesn't detect the property, try evaluating it directly using the above syntax.)

  <profiles>
    <profile>
      <id>myNeededProfile</id>
      <activation>
        <activeByDefault>false</activeByDefault>
        ...
        <property>
          <name>offline</name>
          <value>true</value>
        </property>
        ...
      </activation>
      ...
    </profile>
  </profiles>

I believe that the Maven Help Plugin can guide this development by computing which profile will be active under certain conditions.

I also think that this could be accomplished more simply by explicitly invoking a profile from the command line each time offline mode is requested.

mvn groupId:artifactId:goal -o -P profile-1,profile-2

Or, even more straightforwardly, by having two separate settings files and subbing them out specifically for the offline/online operations. You could write a command-line wrapper in whatever OS environment you're using to detect the offline request, then move and rename the files before executing the Maven commands, then move them back upon completion.

like image 37
ingyhere Avatar answered Sep 20 '22 12:09

ingyhere