Cannot depend on a project published with 'maven-publish'

I have a gradle project that also contains a pom.xml (since we need to use m2e). When I build this project I need to use the existing pom.xml file instead of the one generated by Gradle. I use the ‘maven-publish’ plugin and configure my publications:

publishing {
  publications {
    maven(MavenPublication) {
      pom.withXml { provider ->
        def builder = provider.asString()
        builder.length = 0
        builder.append(file("pom.xml").text)
      }
      from components.java // Make sure the classes is also added to the jar file
    }
  }
...

When I build with ‘gradle clean publishToMavenLocal’ jar and pom.xml files are installed into .m2. I have another plain maven project where I need to depend on the above installed artifact:

<dependency>
   <groupId>com.samples</groupId>
   <artifactId>local-gradle-project</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </dependency>

but it fails to resolve with:

Missing artifact com.samples:local-gradle-project:jar:1.0.0-SNAPSHOT

I have noticed that the META-INF folder is empty in the installed archive:

.m2\repository\com\samples\local-gradle-project\1.0.0-SNAPSHOT\local-gradle-project-1.0.0-20130515.090150-1\META-INF

In a plain maven project this folder contains a ‘maven’ folder with the pom.xml.

Have dependencies for artifacts installed with ‘maven-publish’ been tested/expected to work?

The META-INF thing is a red herring I think. I’m not aware of any part of the Maven protocol that requires the pom in the META-INF dir, or any tooling that uses it.

As for the missing artifact, can you please run with ‘-I’ so we can see where it is trying to find the artifact.

I guess you mean -X (in maven)? It simply point to the repo that I mirror in the settings.xml file. If I use:

apply plugin: 'maven'

instead of:

apply plugin: 'maven-publish'

and build with ‘install’ it works (the installed artifact can be seen from my external maven project).

I have found the following difference. In the artifact installed with ‘maven-publish’ plugin:

maven-metadata.xml

In the artifact installed with ‘maven’ plugin (or when installing a plain maven project with mvn) its called:

maven-metadata-local.xml

It does not help to rename it manually.

I have also tried to build a gradle project using the maven-publish plugin WITHOUT specifying pom.withXml and get the same problem

I think you’re hitting this issue: http://forums.gradle.org/gradle/topics/maven_publish_plugin_publishes_snapshot_versions_to_mavenlocal_using_setunique_true

Is there any way you could try with a non snapshot version to rule this in/out?

If I remove the SNAPSHOT qualifier it works.

The reason why we would like to use the maven-publish plugin is that it makes it possible to avoid installing into .m2. When using the maven plugin and running the ‘uploadArchives’ task artifacts also get installed with a unique timestamp corresponding to the above described problem.

Until we fix GRADLE-2762, you could use this workaround: http://forums.gradle.org/gradle/topics/override_location_of_the_local_maven_repo