Can I retrieve dependencies from Maven repositories?

Can I use jars from my company’s in house maven repository or maven central in my Gradle projects?

Yes, Gradle can read from Maven repositories and understands the pom.xml.

See this section of the chapter on dependency management in the user guide.

as of gradle-1.0-rc-1 use the –recompile-scripts option

Also, in the build.gradle , as the documentation suggests, you can add your project lib directory as a Maven dependency like so, although I suspect it copies the files into your local Maven .m2 repo? I can’t wait to actually try this :

repositories {
    flatDir {
        dirs 'lib'
    }
    flatDir {
        dirs 'lib1', 'lib2'
    }
}

A ‘flatDir’ repo is simply a flat directory containing artifacts that are matched by their filename. It is not in any way related to Maven.

Something that I find missing in gradle is the following: I would like to use a local directory as gradle repository, but because the flatDir repository is a bit rudimentary, I would like this local directory to be in maven format… Let me clarify:

  • I do not wish to use the .m2 directory, nor do i wish to define a repository.xml. This is the maven way. I want a concept similar to flatDir.

  • Yet maven has something very nice that gradle wisely allows to reuse. You can point gradle to a local maven repository. But again, repeat: I do not wish this to be the .m2 repository.

  • All of this works actually quite fine, except for one thing… I’m missing a utility that allows to setup a randomly chosen local directory with all the required 3rd party libs. I’ve looked at the maven dependency plugin to do this for me, but unfortunately it nearly does what I want but not exactly.

What I want to do, is perhaps something like here, http://ianp.org/2011/11/04/installing-to-the-local-maven-repo-with-gradle/, but I’m not sure if I fully understand that link. I would also need some more explanation + if the mentioned link is really it, could this be mentioned somewhere in the docs?

Best regards,

Steven G

I’m not sure if I understand your use case. It is very simple with Gradle to reuse any local Maven repository (not .m2) for retrieving dependencies and publishing artifacts. What exactly do you mean with: setup a randomly chosen local directory with all the required 3rd party libs? What is your use case here?