简体   繁体   中英

Jenkins/Artifactory - Unable to find method create()

I am moving some builds from bamboo over into jenkins, using the same gradle build scripting to build an application. With artifactory turned off, the build is successful, but when turned on it fails with:

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.

The initialization script is being created by the artifactory plugin and looks like:

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)
            }
        }
    }
}

We are using gradle 1.5 for this project, the version has been declared in 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')

You are using the latest version of Artifactory plugin and build-info-extractor-gradle but your gradle version is old. Try using latest version gradle 3.1

If your grade script already applies the "com.jfrog.artifactory" plugin, then in the Jenkins job you should set the "Project uses the Artifactory plugin" option, to make sure Jenkins does not add the initialization script. Bamboo has the same check box for Gradle Artifactory tasks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM