15

I build a jar file without using Gradle Jar task (I need to be using Ant task for that inside my task). How do I configure uploadArchives to be able to install JAR in specified repository.

I have tried to override default artifact with

uploadArchives {
    repositories {
        mavenDeployer {
            // some Maven configuration
        }
    }
}

artifacts {
    archives file: file('bin/result.jar')
}

but I'm getting an error that there may not be 2 artifacts with the same type and classifier, which means this configuration adds rather that overrides configuration.

1 Answer 1

22

You are right, artifacts closure can only add artifacts to the given configuration (see ArtifactHandler API).

You have two options:

1) Add an artifact filter as described here (see ch. 45.6.4.1. "Multiple artifacts per project"). If you use this, try declaring your archives configuration like:

artifacts {
  archives file: file('bin/result.jar'), name: 'result', type: 'jar'
}

This way, you something like this in your artifact filter:

addFilter('result') {artifact, file ->
  artifact.name == 'result'
}

2) Upload it as a separate maven module. If result.jar is the only jar you are uploading this may be a good solution.

configurations {
  resultArchives
}

uploadResultArchives {
  repositories {
    mavenDeployer {
      repository(url: "same/url/here")
    }
  }
}

artifacts{
  resultArchives file: file('bin/result.jar')
}

Hope this helps.

4
  • Thanks for the solution. The latter worked in my case as a charm. Jul 16, 2012 at 13:52
  • I get an error Gradle DSLmethod not found 'uploadResultArchive' , I have applied plugin maven. Any other plugin required
    – sver
    Mar 31, 2016 at 12:14
  • 1
    @sver I guess he meant uploadArchives
    – zaxme
    May 15, 2017 at 9:54
  • Does this create a pom.xml?
    – wheeler
    Nov 29, 2018 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.