How to upload a collection of Jar files generated by imported ANT Tasks?


(Marcello de Sales) #1

Hi all,

How can I upload a collection of existing Jars to a Maven repository? The Jar is built from an ANT Task imported, and used as a dependency to my task… The Jars don’t have version information, so they should ALL receive the same version number when they are uploaded…

apply plugin: ‘maven’

version = “6.1.1”

ant.importBuild “$projectDir/tools/ant/package.xml”

uploadArchives(dependsOn: [“oahu-jar”, “client-sdk-jar”, “common-jar”]) << {

// the dependencies will generate “oahu.jar”, “saturn_client_sdk.jar”, “common.jar”

// UPLOAD THE DEPENDENCIES LISTED ABOVE LOCATED AT the subdirectory “build/”

description = “Uploads the generated jar ${archivesBaseName}-${version}.jar to ${cn_mvn_serverUrl}”

repositories.mavenDeployer {

repository(url: “${cn_mvn_releaseUrl}”) {

authentication(userName: “${cn_mvn_username}”, password: “${cn_mvn_password}”)

}

} }

I have the Maven repositories configuration already working from another project… But the Maven plugin uploads the Jar generated by the Jar task from the Java plugin… This time I’m only using the Maven plugin to upload existing jars that are generated from an ANT task… The result should be

“oahu-6.1.1.jar”, “saturn_client_sdk-6.1.1.jar”, “common-6.1.1.jar”… all uploaded to the repository…

thanks Marcello


(Marcello de Sales) #2

Looking at the documentation, the property “artifacts” is read-only… So, how can I give one or more jars to the uploadArtifacts to be uploaded?

http://www.gradle.org/current/docs/dsl/org.gradle.api.tasks.Upload.html#org.gradle.api.tasks.Upload:artifacts

Marcello


(Peter Niederwieser) #3

You can add artifacts produced by other Jar tasks with “artifacts { … }”. I don’t know of a good way to publish arbitrary (Jar) files at this time. You could try to work around this limitation by adding some fake Jar tasks. Another question is how to generate and publish POMs for these Jars to make them resolvable.


(Peter Niederwieser) #4

Actually there seems to be a way to publish arbitrary files, if you are happy to do a bit of coding. In that case you could create your own org.gradle.api.artifacts.PublishArtifact’s and assign them to a configuration inside the project.artifacts {} block.


(Marcello de Sales) #5

Hi Peter,

Is there any “How to” on extending a gradle project with my own Publish Artifact?

  1. Is there a reference implementation to create a new “PublishArtifact”? 2. Where should that new class/plugin be created? compiled? Added to Jar? 3. Do I need the Gradle source-code for that? Could I just create a groovy class to do that?

I’m still not sure how to implement that…

thanks Marcello


(Peter Niederwieser) #6

ad 1. There is org:gradle:api:internal:artifacts:publish:DefaultPublishArtifact (replace colons with dots, ran into some escaping issues), but it’s an internal class. You can either use that, or create your own implementation. ad 2. In the build script, or in the buildSrc directory. ad 3. No. Yes.