Gradle没有在Jenkins中选择正确版本的war文件

时间:2015-06-17 19:57:24

标签: gradle spring-boot maven-deploy-plugin

Gradle有一个问题,它用于将Spring启动应用程序部署到云代工厂。 maven.deployer没有按照gradle中指定的命名约定选择正确版本的war文件。战争文件在构建/分发中成功创建,但上传到任务没有正确选择。任何帮助都会很棒。

获取错误:

:uploadArchives (Thread[main,5,main]) completed. Took 1.378 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':uploadArchives'.
> Could not publish configuration 'archives'
   > Error deploying artifact 'com.*****:***-SSO_RC:war': Error deploying artifact: Failed to transfer file: http://*******/releases/com****-SSO_RC/0.1.0/****-SSO_RC-0.1.0.war. Return code is: 400

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.

BUILD FAILED

的build.gradle

version "0.1.0"  //Art added Snapshot to version
group "com*****"

project.ext.test = 'test'

// Define property defaults if they don't exist
if( !project.hasProperty('classifier' ) ){
    ext.classifier = 'LOCAL'
}
if( !project.hasProperty('buildNumber' ) ){
    ext.buildNumber = '0'
}

ext.isSnapshot = (ext.classifier == "RELEASE" || ext.classifier.contains("RC" ) ) ? false : true

apply plugin: "maven"
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
apply plugin: 'spring-boot'
apply plugin: 'cloudfoundry'
apply plugin: 'idea'
apply plugin: 'eclipse'

buildscript {
    repositories {
        //mavenCentral()
        maven { url  nexusPublicRepoURL }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")
        classpath("org.springframework:spring-webmvc:4.1.6.RELEASE")
        classpath "org.cloudfoundry:cf-gradle-plugin:1.1.0"
    }
}


// Uses JDK 7
sourceCompatibility = 1.7
targetCompatibility = 1.7


// 1. Get dependencies from Maven local repository
// 2. Get dependencies from Maven central repository
repositories {
    maven { url  nexusPublicRepoURL }
    //mavenCentral()
}

//Project dependencies
dependencies {
    compile 'ch.qos.logback:logback-classic:1.1.2'
    compile 'org.springframework:spring-webmvc:4.1.6.RELEASE'
    compile 'jstl:jstl:1.2'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.5.3'
    //include in compile only, exclude in the war
    providedCompile 'javax.servlet:servlet-api:2.5' 
    // compile("org.springframework.boot:spring-boot-starter-web")
    //providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
}

/*configurations {
    providedRuntime
}*/

eclipse {
    classpath {
         containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
         containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7'
    }
}


uploadArchives {
    repositories.mavenDeployer {
        repository(url: nexusReleaseRepoURL) {
             logger.info("${nexusReleaseRepoURL} is nexusReleaseRepoURL")
            authentication(userName: nexusUsername, password: nexusPassword)
        }
        snapshotRepository(url: nexusSnapshotRepoURL) {
            authentication(userName: nexusUsername, password: nexusPassword)
        }
    }
}

if( project.hasProperty( 'development' ) ){
    cloudfoundry{
        host = '***-ssodev'
        space = 'development'
        target = 'https://api.****.com'
        domain = '****.com'
        env = [
        "JBP_LOG_LEVEL": "DEBUG"
        ]
        services {
            "syslog-drain" {
                label ="syslog-drain"
            }

        }
    }
} else if ( project.hasProperty( 'production' ) ) {
    cloudfoundry {
        host = '***-sso'
        space = 'production'
        target = 'https://api.*****.com'
        domain = '****.com'

        services {
            "syslog-drain" {
                label ="syslog-drain"
            }

        }
    }
}

cloudfoundry {
    username = cfUsername
    password = cfPassword
    application = '****'
    //file = war.outputFile
    file = file("build/distributions/" + buildArchiveName())
    logger.info("${file} is file inside Cloudfoundry")
    memory = 1024
    instances = 1
    organization = "***-org"
    trustSelfSignedCerts = "true"
}

bootRepackage {
    mainClass = '<%= packageName %>.Application'
 }

war {
    archiveName = buildArchiveName()
    logger.info("${archiveName} is archiveName")
    destinationDir = file('build/distribution/')
}   

def buildArchiveName(){
    if( project.hasProperty('archiveBuildNumber' ) ){
        return "****sso-${version}-${classifier}.${archiveBuildNumber}.war".toString()
    }
    else {
        return "****sso-${version}-${classifier}.${buildNumber}.war".toString()
    }
}

1 个答案:

答案 0 :(得分:0)

这个问题已经解决了。我是gradle的新手,实现的解决方案只是将所有内容添加为版本,而不是像版本+分类器+ buildNumber(jenkin)那样保持不同。 war任务应该像basename + version一样,而不是调用archiveName。