2014-03-12 67 views
53

我是Gradle和Artifactory的新手,我想將jar文件上傳到Artifactory。 這是我的build.gradle文件。使用gradle將神器上傳到artifactory

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' //The Artifactory repository key to publish to 
     username = 'publisher'  //The publisher user name 
     password = '********'  //The publisher password 
     maven = true 
    } 
    } 
} 

artifactoryPublish { 
    dependsOn jar 
} 

運行artifactoryPublish任務後,構建成功,如下所示。

> 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 

但是,沒有什麼東西發送到Artifactory除了構建信息。

任何幫助將非常感激

通恰伊

編輯:

正如JBaruch提到的,我已經添加

apply plugin: 'maven-publish' 

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

,並默認部分artifactory的任務

defaults { 
    publications ('mavenJava') 
} 

現在,它的工作。

感謝

+2

感謝您提供非常有幫助的問題和更新。一個註釋幫助了我:'defaults'實際上進入'artifactory.publish'內部,而不僅僅是在根'artifactory'任務中。 –

+2

我在博客中總結了這一點:http://buransky.com/scala/publish-jar-artifact-using-gradle-to-artifactory/ –

+1

當我嘗試它時:'錯誤:(x,0)可能在SoftwareComponentInternal set上找不到屬性'java'。你能發佈完整的腳本嗎? –

回答

37

那是因爲你沒有任何publications做。 artifactory-publish pluginmaven-publish plugin一起使用並上傳publications

如果您喜歡使用the old maven plugin,則需要artifactory plugin,而不是artifactory-publish

看看官方文檔的Overview part in "Working with Gradle" page

+5

嗨JBrauch感謝您的迴應。爲了幫助其他人也有同樣的問題,我在帖子中添加了缺少的部分。 – tuncaysenturk

+7

我希望artifactory的人來...因爲文檔中沒有提及'maven-publish'。感謝@Jaruaru的幫助! http://www.jfrog.com/confluence/display/RTF/Gradle+1.6+Publishing+Artifactory+Plugin –

+0

你可以認爲我是來自artfactory的人:) :) [Here's](http://www.jfrog。 com/confluence/display/RTF/Working + with + Gradle)官方文檔中的解釋。將它添加到答案中。 – JBaruch

6

我得到了這個工作。我實際上是使用已經創建的jar,所以我使用下面的代碼來指定我要上傳的jar:

publishing { 
    publications { 
     mavenJava(MavenPublication) { 
      // from components.java 
      artifact file("path/jar-1.0.0.jar") 
     } 
    } 
} 
相關問題