2017-08-26 53 views
1

我花了很多時間通過jenkins部署spring引導應用程序。但是我一直在失敗。Spring引導 - gradle Intellij Idea構建和Jenkins構建結果不一樣。

在我的地方,執行gradle這個bootRepackage命令建立一個jar文件中的IntelliJ IDEA和它是確定運行jar文件(命令java -jar -Dspring.profile.active=user ABC.jar

所以我註冊這個命令詹金斯,並通過Publish Over SSH與發送jar以下步驟。

  1. bootRepackage --stacktrace -x test --refresh-dependencies
  2. 發送jar文件的Gradle調用腳本,服務器
  3. java -jar -Dspring.profile.active=user ABC.jar

執行的問題是一些自動裝配bean的變空,其在我的地方沒有問題。請檢查我的build gradle腳本並給我一些建議。

buildscript { 
    ext { 
     springBootVersion = '1.5.1.RELEASE' 
     springBootStarterVersion = '1.5.6.RELEASE' 
     infinispanVersion = '8.2.6.Final' 
     coreVersion = '0.0.1-SNAPSHOT' 
    } 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") 
    } 
} 

apply plugin: 'eclipse' 
apply plugin: 'org.springframework.boot' 
apply plugin: 'war' 

jar { 
    baseName = 'ABC' 
    manifest { 
     attributes('Main-Class': 'net.ion.ice.Ice2Application') 
    } 
} 

bootRepackage { 
    withJarTask jar 
    mainClass = 'net.ion.ice.Ice2Application' 
} 

war { 
    baseName = 'ABC' 
    version = "${coreVersion}" 
    enabled = false 
    manifest { 
     attributes('Main-Class': 'net.ion.ice.Ice2Application') 
    } 
} 

version = '0.0.1-SNAPSHOT' 
sourceCompatibility = 1.8 

repositories { 
    maven { 
     url 'http://my-repo.com/nexus/content/groups/public/' 
     name 'my-repo' 
    } 

} 

dependencies { 

    compile("org.springframework.boot:spring-boot-starter-web:${springBootStarterVersion}") 
    compile("org.springframework.boot:spring-boot-starter-tomcat:${springBootStarterVersion}") 
    compile("org.springframework.boot:spring-boot-starter-security:${springBootStarterVersion}") 
    compile('org.springframework.boot:spring-boot-configuration-processor') 
    compile('org.apache.commons:commons-lang3:3.5+') 
    compile('commons-net:commons-net:3.4+') 
    compile('commons-io:commons-io:2.5+') 
    compile('com.fasterxml.jackson.core:jackson-databind:2.8.6+') 
    compile('com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.8.6+') 

    // yml parser 
    compile ('com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.8.9') 

    compile('ch.qos.logback:logback-access:1.2.3') 
    compile('net.logstash.logback:logstash-logback-encoder:4.8+') 

    compile ("org.eclipse.persistence:javax.persistence:2.1.1") 

    compile("org.infinispan:infinispan-embedded:${infinispanVersion}") 
    compile("org.infinispan:infinispan-query:${infinispanVersion}") 
    compile('io.jsonwebtoken:jjwt:0.7.0') 

    compile("org.springframework:spring-jdbc") 
    compile("org.apache.commons:commons-dbcp2:2.1.1") 
    compile('com.oracle:ojdbc8:12.2.0.1')      //oracle 
    compile('org.projectlombok:lombok:1.16.16') 
    runtime('org.springframework.boot:spring-boot-devtools') 
    testCompile("org.springframework.boot:spring-boot-starter-test:${springBootStarterVersion}") 
    testCompile("com.microsoft.sqlserver:mssql-jdbc:6.2.1.jre8") 
} 
+0

這似乎是一個環境問題。當您在本地運行jar時,可能是指向服務器上找不到的本地資源?檢查日誌?比較兩個jar並查看哪些文件不同(如果有的話)。比較環境變量。我看到你使用'spring.profile.active = user',猜測會在服務器上找不到'application-user.properties'(當地存在)? – alexbt

+0

@alexbt其實,那2個war文件看起來像有相同的內容(大小一樣)。我用'gradle build --refresh-dependencies --stacktrace -x test'製作war文件。這個命令可能是錯誤的?另外,'並行'關鍵字可以影響到這一點? (我沒有建立任何東西,但只有一個春季啓動Web應用程序) –

+0

@alexbt上一個是構建命令,我用'java -jar -Dspring.profile.active = user ABC.war'運行應用程序,我可以看到profilename在日誌。 –

回答

0

我發現它與構建環境無關。這只是一個代碼問題。有人用空值再次覆蓋Bean。無論如何,謝謝你幫助我。 (尤其是@alexbt)