2015-06-17 37 views
0

我有一个Gradle问题,它用于将Spring引导应用程序部署到云代工厂。根据gradle中指定的命名约定,maven.deployer不会选择war文件的正确版本。 war文件是在buil/distributions中成功创建的,但是没有通过uploadarchive任务正确拾取。任何帮助都会很棒。Gradle在Jenkin中没有选择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() 
    } 
} 
+0

此问题上的cloudfoundry标记具有误导性,因为uploadArchives任务与Cloud Foundry无关。 –

+0

这个问题对我来说已经解决了。我对gradle很陌生,实现的解决方案只是将所有内容添加为版本,而不是像版本+分类+ buildNumber(jenkin)那样保持版本不同。战争任务应该像basename +版本,而不是调用archiveName。 – Shamseer

回答

0

问题解决了我。我对gradle很陌生,实现的解决方案只是将所有内容添加为版本,而不是像版本+分类+ buildNumber(jenkin)那样保持版本不同。战争任务应该像basename +版本,而不是调用archiveName。