Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: How to upload custom JAR file to Maven repository

Tags:

maven

gradle

jar

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.

like image 867
Wojtek Erbetowski Avatar asked Jul 16 '12 12:07

Wojtek Erbetowski


1 Answers

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.

like image 64
rodion Avatar answered Oct 24 '22 18:10

rodion