Include dependencies with uploadArchives


(Tim Dudgeon) #1

I’m using the uploadArchives task to load my projects artifact into a local maven repo like this:
uploadArchives {
repositories {
mavenDeployer {
repository(url: “file:///var/maven_repo/”)
}
}
}

This works fine, but I also want to include the project’s dependencies (and transient dependencies) in the repo so that the repo is completely “self contained”.
How can I do this?

Thanks
Tim


(Francois Ritaly) #2

Do you expect the “self contained” repo to contain the project dependencies plus their corresponding descriptor (that is POM file) ?

It’s probably possible to find a way to publish the 3rd party dependencies to the Maven repository (by using the ‘maven-publish’ plugin) but it won’t be possible to also publish the corresponding 3rd party POM file. Your repo will end up with POM files corresponding to your own project.


(Francois Ritaly) #3

Test with ./gradlew and check build/local-repo (in particular the POM files).

apply plugin: 'java'
apply plugin: 'maven-publish'

defaultTasks 'clean', 'publish'

repositories {
  mavenCentral()
}

dependencies {
  compile 'commons-lang:commons-lang:2.4'
  compile 'junit:junit:4.11'
}

group = 'com.company.project'
version = '1.0.0-SNAPSHOT'

publishing {
  publications {
    mavenJava(MavenPublication) {
      from components.java
    }
  }
  repositories {
    maven {
      url new File(buildDir, 'local-repo').toURL()
    }
  }
}

configurations.compile.resolvedConfiguration.resolvedArtifacts.eachWithIndex { resolvedArtifact, n ->
  println resolvedArtifact

  project.publishing {
    publications {
      "maven${n}"(MavenPublication) {
        artifact(resolvedArtifact.file) {
          groupId = resolvedArtifact.moduleVersion.id.group
          artifactId = resolvedArtifact.moduleVersion.id.name
          version = resolvedArtifact.moduleVersion.id.version
          classifier = resolvedArtifact.classifier
        }
      } 
    }
  }
}

(Tim Dudgeon) #4

Francois,
Thanks very much for that. It seems to work, and to my (largely untrained) eye the pom files seem to be present and correct.
And yes, I was wanting my local repo to behave like it was a subset of maven central containing all my projects dependencies and with my project files also present.
Thanks
Tim


(Thorsten Schöning) #5

version = resolvedArtifact.moduleVersion.id.version

This line results in all artifacts getting the same version, 3.2.9 in my case, pretty much like when I’m hard-coding ‘1.0.0’ instead. But I’m absolutely sure that not all artifacts have that same version. Any idea on what might get wrong?