Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
443 views
in Technique[技术] by (71.8m points)

publish - 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

apply plugin: 'maven-publish'

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
}

and defaults section to artifactory task

defaults {
   publications ('mavenJava')
}

Now it works.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...