Struggling to share sub-projects in other project

I am struggling with sharing artifacts between multiple projects on my machine using Gradle 2.3.

My first project has three sub-projects; common, client and server. I want to publish the code, source and java docs of the common and client sub-projects to my local repository so they can be included in my second project. I have a couple issues. I can publish the snapshot with time stamps in the file names but the other project does not pick them. The java docs has multiple index.hmtl files instead of being merged.

Here is the some of build.gradle script from the first project with three sub-projects.

apply plugin: 'java'

project(':contact-service-common') {
}

project(':contact-service-client') {
    apply plugin: 'maven'

    dependencies {
        compile project(':contact-service-common')

        compile("org.springframework.cloud:spring-cloud-starter-eureka:${springCloudVersion}")
    }
    
    jar {
        from files(
            project(':contact-service-common').sourceSets.main.output
        )
    }

    task sourcesJar(type: Jar, dependsOn: classes) {
        classifier = 'sources'
        from files(
            sourceSets.main.allSource,
            project(':contact-service-common').sourceSets.main.allSource
        )
    }

    task javadocJar(type: Jar, dependsOn: javadoc) {
        classifier = 'javadoc'
        from(
            javadoc.destinationDir,
            project(':contact-service-common').javadoc.destinationDir
        ) 
    }

    artifacts {
        archives jar
        archives sourcesJar
        archives javadocJar
    }
    
    uploadArchives {
        repositories {
            mavenDeployer {
                repository(url: "file://${System.properties['user.home']}/.m2")
            }
        }
    }
}

The published artifacts are almost what I was expecting. The classes jar and the sources jar contain the files from both the common and the client sub-projects. The javadoc jar contains the javadocs of both projects but multiple index.html and other root files. I would like one index.html that combines the two sub-projects.

ls ~/.m2/repository/com/wstrater/contact-service-client/0.0.1-SNAPSHOT/contact-service-client-0.0.1-20150508.150127-11*
~/.m2/repository/com/wstrater/contact-service-client/0.0.1-SNAPSHOT/contact-service-client-0.0.1-20150508.150127-11.jar
~/.m2/repository/com/wstrater/contact-service-client/0.0.1-SNAPSHOT/contact-service-client-0.0.1-20150508.150127-11-javadoc.jar
~/.m2/repository/com/wstrater/contact-service-client/0.0.1-SNAPSHOT/contact-service-client-0.0.1-20150508.150127-11.pom
~/.m2/repository/com/wstrater/contact-service-client/0.0.1-SNAPSHOT/contact-service-client-0.0.1-20150508.150127-11-sources.jar

jar -tvf ~/.m2/repository/com/wstrater/contact-service-client/0.0.1-SNAPSHOT/contact-service-client-0.0.1-20150508.150127-11-javadoc.jar | grep "index\.html"
  2595 Fri May 08 11:01:26 EDT 2015 index.html
  2686 Fri May 08 11:01:24 EDT 2015 index.html

The next problem is I can not include the client jar in another project.

Here some of the build.gradle of the other project.

subprojects {
    apply plugin: "java"

    sourceCompatibility = 1.7
    targetCompatibility = 1.7

    repositories { 
        mavenLocal()
        mavenCentral()
    }

    dependencies {
        compile("com.wstrater:contact-service-client:${version}")
    }
}

project(':passport-service-client') {
    dependencies {
        compile project(':passport-service-common')
    }
    
    jar {
        from files(
            project(':passport-service-common').sourceSets.main.output
        )
    }
}

I get the following error.

./gradlew clean test
:passport-service-client:clean UP-TO-DATE
:passport-service-common:clean UP-TO-DATE
:passport-service-server:clean UP-TO-DATE
:passport-service-common:compileJava

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all dependencies for configuration ':passport-service-common:compile'.
> Could not find com.wstrater:contact-service-client:0.0.1-SNAPSHOT.
  Required by:
      com.wstrater:passport-service-common:0.0.1-SNAPSHOT

The Maven metadata lookls like it references the correct jar files.

cat ~/.m2/repository/com/wstrater/contact-service-client/0.0.1-SNAPSHOT/maven-metadata-remote.xml
<?xml version="1.0" encoding="UTF-8"?>
<metadata>
  <groupId>com.wstrater</groupId>
  <artifactId>contact-service-client</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <versioning>
    <snapshot>
      <timestamp>20150508.150127</timestamp>
      <buildNumber>11</buildNumber>
    </snapshot>
    <lastUpdated>20150508150127</lastUpdated>
  </versioning>
</metadata>

I am new to Gradle and Groovy and would be appreciated any help. My searches have found snippets of build script but I have not found an complete end-to-end example.

Wes.

I didn’t have a deep look but the issue is probably that you are not publishing to a snapshot repository. Use snapshotRepository instead of repository for the mavenDeployer.

uploadArchives.repositories.mavenDeployer.snapshotRepository

Sorry for the delay in getting back to you but had computer issues this weekend. I tried using a snapshotRepository and got the same results. I removed the Maven directory and tried again but got the same error.

Could not resolve all dependencies for configuration ':passport-service-common:compile'.
> Could not find com.wstrater:contact-service-client:0.0.1-SNAPSHOT.
  Required by:
      com.wstrater:passport-service-common:0.0.1-SNAPSHOT

Maybe I did not implement your suggestion properly. Here is what I changed in project(’:contact-service-client’).

uploadArchives {
    repositories {
        mavenDeployer {
            snapshotRepository(url: "file://${System.properties['user.home']}/.m2")
        }
    }
}

Looking at the Maven directory and metadata file, I do not see much difference other than time stamp and build number. This is how I am trying to include it in my other projects using the subprojects block.

dependencies {
    compile("com.wstrater:contact-service-client:${version}")
}

Thanks, Wes.

If you want to publish into the Maven local repository, then your URL is incorrect. It should be file://${System.properties['user.home']}/.m2/repository.

Keep in mind that you can use any local directory. It doesn’t have to be the one used by Maven local except if you are actually consuming the artifact from Maven.

Thank you, I was able to get a clean test in my second project.

Wes.