Publish a pre-built jar to a Maven repository with dependencies

(robert) #1

Hello. How do I publish a pre-built Jar to Maven and at the same time provide the dependencies to include in the pom.xml file?

I have a jar that is being pre-built by an external script. I need to publish this jar to our Maven repo (nexus) along with dependencies that I can add to the dependencies closure in build.gradle. I have been able to get a pre built jar published to a Maven repo using the artifacts closure but it ignore the dependencies closure. If I add the java plugin then Maven plugin creates a pom with the dependencies but will upload a zero byte jar file. I guess this is because the Java plugin expects to compile source in the src dir, which does not exist in this project.

Is there a way I can ‘inject’ a pre-built Jar into the Java plugin process so that I can the jar uploaded along with the dependencies? Or am I missing something else that’s obvious?

Of course the best thing would be for the pre-built Jar’s build process to outline its dependencies and upload to Maven but unfortunately it’s a 3rd party piece of software and we have no control.

Below script publishes a zero kb jar file…

apply plugin: 'java'
apply plugin: 'maven'
  jar = file(projectHome + '/build/lib').listFiles()[0]
  configurations {
  dependencies {
    runtime 'org.apache.tika:tika-app:1.3'
  artifacts {
    archives jar
  uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "")
            pom.version = tag
            pom.artifactId = "artifact"
            pom.groupId = "group"

Many thanks! Rob

(Peter Niederwieser) #2

It might not be easy to achieve this, as things aren’t designed to support this use case. I’d consider publishing the artifact manually. Alternatively, browsing the docs of ‘Project.archives’ in the Gradle Build Language Reference and/or experimenting with the new ‘maven-publish’ plugin (see user guide) might help.