2016-11-07 187 views
0

我正在將一些構建從竹轉移到jenkins,使用相同的gradle構建腳本構建應用程序。隨着artifactory的關閉,構建成功,但事實證明,當失敗:Jenkins/Artifactory - 無法找到方法create()

09:22:08.568 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception. 
09:22:08.569 [ERROR] [org.gradle.BuildExceptionReporter] 
09:22:08.569 [ERROR] [org.gradle.BuildExceptionReporter] * Where: 
09:22:08.569 [ERROR] [org.gradle.BuildExceptionReporter] Initialization script '/tmp/init-artifactory2218166479825929225gradle' line: 20 
09:22:08.570 [ERROR] [org.gradle.BuildExceptionReporter] 
09:22:08.570 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong: 
09:22:08.570 [ERROR] [org.gradle.BuildExceptionReporter] Failed to notify build listener. 
09:22:08.570 [ERROR] [org.gradle.BuildExceptionReporter] > Failed to notify build listener. 
09:22:08.571 [ERROR] [org.gradle.BuildExceptionReporter] > Could not find method create() for arguments [artifactoryPublish, class org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask] on task set. 

初始化腳本由artifactory的插件創建的,看起來像:

import org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin 
import org.jfrog.gradle.plugin.artifactory.task.ArtifactoryTask 

initscript { 
    dependencies { 
     classpath fileTree('/var/lib/jenkins/cache/artifactory-plugin/2.7.2') 
    } 
} 

addListener(new BuildInfoPluginListener()) 
class BuildInfoPluginListener extends BuildAdapter { 

    def void projectsLoaded(Gradle gradle) { 
     gradle.startParameter.getProjectProperties().put("build.start", Long.toString(System.currentTimeMillis())) 
     Project root = gradle.getRootProject() 
     root.logger.debug("Artifactory plugin: projectsEvaluated: ${root.name}") 
     if (!"buildSrc".equals(root.name)) { 
      root.allprojects { 
       apply { 
        apply plugin: ArtifactoryPlugin 
       } 
      } 
     } 

     // Set the "archives" configuration to all Artifactory tasks. 
     for (Project p : root.getAllprojects()) { 
      Task t = p.getTasks().findByName(ArtifactoryTask.BUILD_INFO_TASK_NAME) 
      if (t != null) { 
       ArtifactoryTask task = (ArtifactoryTask)t 
       task.setAddArchivesConfigToTask(true) 
      } 
     } 
    } 
} 

我們使用gradle這個1.5爲這個項目,版本已經在build.gradle中聲明。

的build.gradle:

apply plugin: 'groovy' 
apply from: 'scripts/wrapper.gradle' 
gradleVersion='1.5' 

group = 'com.company.build' 

task testBuildSingle(type: GradleBuild) { 
    buildFile = 'test/single/build.gradle' 
    tasks = ['clean', 'build'] 
} 

task testBuildMulti(type: GradleBuild) { 
    buildFile = 'test/multi/build.gradle' 
    tasks = ['clean', 'build'] 
} 

test.dependsOn('testBuildSingle') 

task dist(type: Copy) { 
    from 'scripts' 
    into("$buildDir/scripts") 
    eachFile({ 
     def file = file("scripts/${it.getPath()}") 
     println file 
     artifacts.add('archives', file) 
    }) 
} 

dist.dependsOn('test') 
+0

正如你可以在'Jenkins Artifactory Plugin'頁面中看到的那樣https://wiki.jenkins-ci.org/pages/viewpage.action?pageId=57182305。 'Artifactory插件2.7.2'需要'Gradle 1.15'。該問題可能是由版本不兼容引起的。 –

+0

我有gradle 1.25插件,我試圖在構建腳本中構建w /不同的gradle v。但它沒有改變。 – James

+0

你可以分享'gradle.build'嗎? –

回答

0

您正在使用最新版本Artifactory的插件和構建信息提取器,但gradle這個你gradle這個版本是舊的。嘗試使用最新版本的gradle 3.1

0

如果您的成績腳本已經應用了「com.jfrog.artifactory」插件,那麼在Jenkins作業中,您應該設置「Project uses the Artifactory plugin」選項,以確保Jenkins不會添加初始化腳本。竹有與Gradle Artifactory任務相同的複選框。