This should be relatively easy to do using either the maven-publish or ivy-publish plugins. What repository format are you publishing to?
In addition to the examples provided in the documentation, if the jar you want to publish is generated external to and before Gradle’s execution, then you can publish the file directly instead of publishing the output of a task or the java component:
apply plugin: 'maven-publish'
ext {
jarToPublish = file( 'ClassesToBePublishedJar.jar' )
}
publishing {
publications {
yourPublicationNameHere( MavenPublication ) {
artifact jarToPublish
/* can specify a classifier if not encoded in the filename
artifact jarToPublish {
classifier 'theClassifier'
}
*/
}
}
repositories {
maven {
url 'http://you.nexus.server/repo'
credentials {
username 'user'
password 'password'
}
}
}
}
If the jar is generated by a task in the Gradle build, then it is best to use the task as the source of the artifact (as shown in the documentation). If the task is not a subclass of AbstractArchiveTask, then something like this will help you:
artifact( tasks.theTask.outputs.files.singleFile ) {
builtBy tasks.theTask // ensures task dependencies are created
}