Problem mixing gradle and maven repositories (Using gradle 1.4)

Maven downloads 3rd party jars into:

.m2\repositories

Gradle download 3rd party jars into:

\.gradle\caches\artifacts-23\filestore

In a gradle project I specify the following order of maven repositories:

mavenLocal()
      maven { url "http://our-artifactory.com" }

But I start seeing errors like:

Artifact 'org.slf4j:slf4j-api:1.6.1@jar' not found.

This artifact is located here (most likely caused by one of my maven projects):

.m2\repository\org\slf4j\slf4j-api\1.6.4\slf4j-api-1.6.4.jar

Its only after deleting it from .m2/repositories that my gradle build continues.

Does gradle not work with maven projects (mixing of local repositories for 3rd party libs)?

As a result I currently cannot use my maven projects and also need to set maven in “Offline” mode in the eclipse preferences.

In a gradle project I specify the following order of maven repositories: >>

mavenLocal() >>

maven { url “http://our-artifactory.com” }

Why do you need to include mavenLocal()? (This has no performance benefit and will actually be slowing things down.) ‘mavenLocal’ is only required if you are producing binaries locally with Maven and then using then in a Gradle build.

Does gradle not work with maven projects (mixing of local repositories for 3rd party libs)?

Yes it should. You definitely shouldn’t need to delete your local M2 repository! Can you put it back, and confirm that you are getting “Artifact ‘foo’ not found.” errors?

In that case, please provide the full output of running gradle with the ‘–debug’ flag. The best way to provide this is via GitHub Gist.

I use mavenLocal() since I produce/install artifacts into my local .m2 using:

apply plugin: 'maven'

These artifacts are then consumed by various other projects that we are developing (as external dependencies).

I will return with the debug output next time I get this problem (I have experienced it for some time now)

Instead of using the Maven cache to share artifacts between your Gradle builds, I would suggest that you use a separate maven repository, and publish the artifacts using ‘gradle uploadArchives’.

You could do something like:

repositories {
    maven {
         name "local-artifacts"
        url "${project.gradle.gradleUserHomeDir}/local-artifacts"
     }
    maven { url "http://our-artifactory.com" }
}
  uploadArchives {
    repositories {
        add project.repositories.local-artifacts
    }
}

That way, you’d be explicitly sharing project artifacts without polluting your repositories with the entire Maven cache.

I already use the uploadArchives to deploy to artifactory. It seems a bit overkill to upload an artifact A to artifactory to be able to use it as a dependency in project B locally.

Further others might be using A from artifactory and I don’t want to break their version by uploading something that I am experimenting with locally (as I see it deploy to artifactory should only be done by the integration server).

mavenLocal is only required if you are producing binaries locally with Maven and then using then in a Gradle build.

how should you share binaries between distinct gradle builds?

OK. There is no built-in Gradle equivalent of ‘maven install’ to publish an artifact to a local repository only. Gradle doesn’t automatically differentiate between different repositories, and you never “install” into the Gradle Cache. (In Maven, the cache and local repository are one-and-the-same).

You could easily script something up by detecting a project property to choose which repository to ‘uploadArchives’ to:

uploadArchives {
    repositories {
        if (project.hasProperty('localInstall')) {
                maven { url "${project.gradle.gradleUserHomeDir}/local-artifacts" }
        } else {
                maven { url "http://our-artifactory.com" }
        }
    }
}

Use ‘gradle -PlocalInstall uploadArchives’ to only install the artifact locally. Use ‘gradle uploadArchives’ to upload to artifactory. (Or switch the flag so that local is the default).

In your consuming build, if you place the local repository first in your list of repositories, locally installed artifacts will be used in preference to those in artifactory.

Use a shared local (filesystem) repository. You can decide where you want this to go.

In general I’d avoid using the Maven cache/repository except for sharing between Maven and Gradle builds. But if that’s really what you want to do, then it should work: we’ll need to see the debug logs of your failed build to work out why it’s not working.