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

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 {
    archives
    runtime
}
  dependencies {
    runtime 'org.apache.tika:tika-app:1.3'
}
  artifacts {
    archives jar
}
  uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "http://build.com/nexus/content/repositories/releases/")
            pom.version = tag
            pom.artifactId = "artifact"
            pom.groupId = "group"
        }
    }
}

Many thanks! Rob

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.