0

I have been "sneaker-netted" a set of jars that I will eventually publish to a Gradle-friendly repo (Artifactory) but that, for the time being, have to stay local on my machine.

I need to use these jars in a Gradle project that not only needs to be able to list these as dependencies but that also uses the Eclipse plugin to resolve dependencies inside my Eclipse IDE.

These jars all have POMs and have their own transitive dependencies (all of which are in typical repos like Maven Central and JCenter, etc.).

I am looking for a way to save these jars somewhere on my file system but then resolve them like they are normal dependencies, including resolution of their transitive dependencies, and also for this to be compatible with however the Gradle Eclipse plugin works under the hood.

Again, the desired outcome would be:

  • Add these jars as dependencies from, say, ~/special-jars/*
  • Whatever dependencies are defined in each "special jar's" POM, resolve those
  • When I run gradle eclipse, Gradle pulls them in from the file system as well

Is this possible to do? If so, how?

smeeb
  • 27,777
  • 57
  • 250
  • 447

2 Answers2

1

Sounds like you want to store your jars in a local maven repository.

Local Maven Repo lives here by default ~/.m2/repository

With a local maven repository the directory structure will be strict for example here is gson on my local

$ ls -d $PWD/*
/Users/some.user/.m2/repository/com/google/code/gson/gson/2.6.2/gson-2.6.2-javadoc.jar
/Users/some.user/.m2/repository/com/google/code/gson/gson/2.6.2/gson-2.6.2-javadoc.jar.sha1
/Users/some.user/.m2/repository/com/google/code/gson/gson/2.6.2/gson-2.6.2-sources.jar
/Users/some.user/.m2/repository/com/google/code/gson/gson/2.6.2/gson-2.6.2-sources.jar.sha1
/Users/some.user/.m2/repository/com/google/code/gson/gson/2.6.2/gson-2.6.2.jar
/Users/some.user/.m2/repository/com/google/code/gson/gson/2.6.2/gson-2.6.2.jar.sha1
/Users/some.user/.m2/repository/com/google/code/gson/gson/2.6.2/gson-2.6.2.pom
/Users/some.user/.m2/repository/com/google/code/gson/gson/2.6.2/gson-2.6.2.pom.sha1

Using this I can use the typical gradle dependency with transitive dependencies.

repositories {
    mavenLocal()
}
dependencies {
    compile "com.google.code.gson:gson:2.6.2"
}

You could import the jars through a flatdir however you will loose the transitive dependencies declared in the pom.

JBirdVegas
  • 10,855
  • 2
  • 44
  • 50
  • I think you missed an important bit of info in your directory listing. You should also see `gson-2.6.2.pom` in the directory which specifies the transitive dependencies – lance-java Nov 15 '16 at 13:51
  • @Lance Java, Good point I've updated the answer to show the full directory content including `pom` and `sha1` files – JBirdVegas Nov 15 '16 at 17:35
0

Further to JBirdVegas' answer, you can use a custom location too. For instance you could use a project subfolder

repositories {
   maven {
      url file("${rootProject.projectDir}/mavenRepo")
   }
}

Or

repositories {
   maven {
      url file("c:/path/to/repo")
   }
}
Community
  • 1
  • 1
lance-java
  • 25,497
  • 4
  • 59
  • 101