How can I set an explicit archive name when doing uploadArchives?

I would like my uploaded archive to simply have the name “foo.jar”. instead of “foo-${version}.jar”. How can I achieve this? My build script is simply as below, which results in the archive being written as “foo-unspecifiedVersion.jar”. Setting version to null or ‘’ does not help.

apply plugin: 'java'
  archivesBaseName = 'foo'
  uploadArchives {
  repositories {
    flatDir {
      dirs file('D:/temp/')
    }
  }
}

jar.archiveName = “foo.jar”

Docs here: dsl:org.gradle.api.tasks.bundling.Jar:archiveName

that changes the jar file name when it is built (jar task), but i want to be able to specify the jar name when it is uploaded via the uploadArchives task.

I still get foo-unspecified.jar when doing your suggestion.

2 Likes

I have exactly the same problem - want to get rid of the “-unspecified” …

Is there really no way to change this behaviour of the uploadArchives task ?

This is still a problem that I am running into using Gradle 1.4. I found a thread that echoes this issue: http://gradle.1045684.n5.nabble.com/Create-an-artifact-with-a-different-version-number-as-the-main-project-td3374437.html

The JIRA issue that was created as a response to that thread is at: http://issues.gradle.org/browse/GRADLE-1382

I hope there will be a fix soon!

To have multiple different jar files in your upload task you have to use pom filter at the moment. have a look at the according section in the userguide http://www.gradle.org/docs/current/userguide/maven_plugin.html#sub:multiple_artifacts_per_project

cheers, René

Forgive me if I’m missing something, but isn’t that specifically for uploading to a maven repository? I’m uploading to a local flatDir and am not having difficulty uploading multiple jars. Specifically, I’m having trouble in that the upload task does not respect the version or the archiveName properties of an artifact.

For example, given the following build.gradle:

apply plugin: 'java'
 version = '1.0-SNAPSHOT'
 group = 'com.some'
  configurations {
    shared
 }
task sharedJar(type: Jar) {
    archiveName = "common-resources.jar"
...
 }
  artifacts {
    shared sharedJar
 }
  uploadShared {
    repositories { add project.repositories.localRepository }
 }

The uploaded file name is “shared-1.0-SNAPSHOT.jar” but it should be “common-resources.jar”

It’s not clear why you’d be using the upload task to copy jars into a ‘flatDir’ repository. Are you using generated ivy.xml metadata files or Maven Pom files, or just the jar files?

If you only need jar files, you might find a simple copy task works better than ‘uploadShared’. If you require the metadata files, then you should be using an ‘ivy’ or ‘maven’ repository with a ‘file’ URL.

The ‘Upload’ task has been designed around publishing artifacts to a structured repository. You might be able to use it to copy files into an unstructured folder (like flatDir) but it wasn’t specifically designed for such use.

After collaboration with a couple coworkers, we came to the same conclusion this afternoon with success. I was stuck in the mindset of our flat directory as a repository, and of taking advantage of built-in tasks. Thanks for your input!