While I was working on dropbox writer, I run into this problem. I have a maven based project that to use dropbox java SDK, but dropbox java SDK is not in any well known Maven repository. So I did some research on add dropbox sdk dependency to maven. After two days of trial and erros I’ve found a few ways to approach this.
First thing I found was to add system path property under dependency configuration, but this solution excludes the library from maven build.
Also I found people suggest that I should create my own maven repository. If you are interested this blogs have details on how to create maven repository in github. While this is a workable solution, I don’t really want to maintain a dedicated maven repository.
The best solution I found was to create an in project repository. The idea is your will create a library folder inside your project. You’ll configure your pom to point to the repository and it will act as a normal maven repository.
To get started first you need to create a library folder under your project, I’ll call this folder libs (make sure it’s in the same folder as your pom). Then you create a sub folder structure under libs and name your library using the following convention.
/groupId/artifactId/version/artifactId-verion.jar
I’ve created the following structure for dropbox sdk library
groupId = dropbox
artifactId = dropbox-sdk
version = 1.3.1
the library file = dropbox-sdk-1.3.1.jar
Next open your pom.xml and add the following block under repositories
<!-- In Project repository --> <repository> <id>in-project</id> <name>In Project Repo</name> <url>file://${project.basedir}/libs</url> </repository>
This will point to you in project repository. The name field can be anything.
Now in the pom.xml you can add dropbox dependency as following
<dependency> <groupId>dropbox</groupId> <artifactId>dropbox-sdk</artifactId> <version>1.3.1</version> </dependency>
Notice the groupId, artificatId and verion follows the pattern described above.
You can add multiple dependencies by creating them in separate folder structure under libs.
This was very helpful. Thanks! Note that instead of constructing the libs directory structure manually, you can also do this:
mvn install:install-file -Dfile=dropbox-sdk-1.3.1.jar -DgroupId=dropbox -DartifactId=dropbox-sdk -Dversion=1.3.1 -Dpackaging=jar -DlocalRepositoryPath=lib -DcreateChecksum=true
This will create the structure for you and also create the checksum metadata to avoid the Maven warning.
Thanks for the information. You have safe my time.
Hi,
great article. You might want to add a more common case when you have domain name like example.com:
/com
/exmaple
/artifactId
Also you can try to use
mvn deploy:deploy-file -Durl=file:///path/to/yourproject/repo/ -Dfile=mylib-1.0.jar -DgroupId=com.example -DartifactId=mylib -Dpackaging=jar -Dversion=1.0
to autoamtically deploy the depedency.
Thanks!