Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload artifact to Artifactory using Gradle

I am a newbie to Gradle and Artifactory and I want to upload a JAR file to Artifactory.

Here is my build.gradle file:

apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'maven' apply plugin: 'artifactory-publish'  groupId = 'myGroup' version = '1.0' def artifactId = projectDir.name def versionNumber = version  artifactory {     contextUrl = 'http://path.to.artifactory' // base artifactory url     publish {         repository {             repoKey = 'libs-releases'   // Artifactory repository key to publish to             username = 'publisher'      // publisher user name             password = '********'       // publisher password             maven = true         }     } }      artifactoryPublish {      dependsOn jar } 

After running the artifactoryPublish task, the build is successful as shown below:

> gradle artifactoryPublish  --stacktrace :compileJava UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE :jar :artifactoryPublish Deploying build info to: http://path.to.artifactory/api/build      BUILD SUCCESSFUL      Total time: 7.387 secs 

However, there is nothing sent to Artifactory except the build info.

Any help will be much appreciated.

Edit:

As JBaruch mentioned, I've added the following:

apply plugin: 'maven-publish'  publishing {     publications {         mavenJava(MavenPublication) {             from components.java         }     } } 

and defaults section to artifactory task:

defaults {    publications ('mavenJava') } 

Now it works.

Thanks.

like image 882
tuncaysenturk Avatar asked Mar 12 '14 13:03

tuncaysenturk


People also ask

How do you upload artifacts to Artifactory?

You log in to Artifactory as an administrator/user which has access to deploy artifacts, click on "Deploy" tab, browse for the Artifactory file and once you select the file, click on "Upload" button.

What is Artifactory in gradle?

The Gradle Artifactory Plugin allows you to deploy your build artifacts and build information to Artifactory and also to resolve your build dependencies from Artifactory. The minimum supported Gradle version is 4.10.

How do I publish on Artifactory?

1. Upload to the Artifactory repository manually. The easiest way, and the least DevOps-friendly way, to upload a JAR to an Artifactory repository is to simply log in to the administrative console, select a target folder and drag and drop the JAR onto the deployment screen.


1 Answers

That's because you don't have any publications. The artifactory-publish plugin works with maven-publish plugin and uploads publications.

If you prefer working with the old maven plugin, you need artifactory plugin, not artifactory-publish.

Take a look at the Overview part in "Working with Gradle" page of the official docs.

like image 56
JBaruch Avatar answered Sep 20 '22 00:09

JBaruch