2
votes

I use both windows and ubuntu for my java development work. I manage a common workspace for them using dropbox. In ubuntu, my dropbox folder resides in home directory, while in windows it resides in a separate partition.

I want to have a common .m2 folder for both windows and linux through dropbox. I understand that by modifying the below line in settings.xml I can achieve it:

  <localRepository>${user.home}/dropbox/.m2/repository</localRepository>

While this works when the dropbox is set in home directory for both ubuntu and windows, this doesn't work for me as I prefer to have my dropbox set up in a completely different partition in windows.

Is there any way I can define a new system variable similar to user.home, say for example user.dropbox.home in both windows and ubuntu to achieve it?

2

2 Answers

3
votes

I was finally able to do it by setting custom user variables as below:

Windows:

_JAVA_OPTIONS
-Duser.dropbox.maven=E:\Dropbox\maven

Linux:

_JAVA_OPTIONS
-Duser.dropbox.maven=/home/creationk/Dropbox/maven

And settings.xml was modified as below:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository>${user.dropbox.maven}/.m2/repository</localRepository>
</settings>
2
votes

I am curious why you would want to have a common .m2 folder? A key purpose of this folder is to maintain a local repository to eliminate unnecessary network traffic.

I would caution against making your local repository not so local. Chances are that you will run into file corruptions and concurrency issues. Jenkins users can attest to that, albeit for different reasons. Dropbox's update protocols will just further get in the way. Rather than thinking of .m2 as a repository, think of it as a cache.

If it is a common repository that you are seeking, I suggest looking into:

Edit:

Given that the intent of sharing .m2 is to create, what the OP calls, a universal repository, the following demonstrates how to configure a file-based repository via Dropbox. Similar techniques can be applied to other shared filesystem mechanisms (e.g. CIFS, NFS, etc.) to deploy and retrieve artifacts.

First, create a private folder in your Dropbox folder named repo.

Next, add the following <distributionManagement> configuration to your project's POM, or in a parent POM shared by all projects, or better yet a profile (but that is another question).

<distributionManagement>
   <repository>
      <id>db-repo</id>
      <url>file:///C:/Users/user/Dropbox/repo</url>
   </repository>
</distributionManagement>

Having done this, whenever you run mvn deploy, the resulting artifacts will be added to or updated in your common repository. The filepath to the repository will vary on different systems. As long as these configurations are set globally in each system, they only have to be set once.

To enable the same and other projects to use artifacts deployed thereunder, add a <repository> configuration for the common repository.

...
<repositories>
   ...
   <repository>
      <id>db-repo</id>
      <url>file:///C:/Users/user/Dropbox/repo</url>
   </repository>
</repositories>

A public Dropbox-based repository can be implement in a similar fashion by creating the repository folder in Dropbox's Public folder. Once created, log in to your Dropbox website and select the repository folder. Use the Share button to retrieve its public URL. This URL should be used for the <repository> configuration. For example,

   <repository>
      <id>db-repo</id>
      <url>https://www.dropbox.com/whatever/dropbox/says/it/should/be</url>
   </repository>