2016-05-10 113 views
0

我用gradle編寫了一個spring-boot應用程序,它運行正常。使用gradle無法安裝spring-boot fat jar到Maven倉庫

我使用bootRepackage構建了一個胖罐子,我添加了maven插件以便可以安裝罐子。

問題是我無法將fat jar安裝到maven倉庫。

  1. 「bootRepackage」構建脂肪jar文件
  2. 安裝依賴於「罐子」相位因此它就建立一個薄罐重寫脂肪jar文件
  3. 薄罐被複制到存儲庫

這裏是我的基地項目gradle這個腳本,請注意,我仍然試圖將其安裝到我的本地庫(我們是一家新公司,我們仍在繼續遠程倉庫)

subprojects { 
group 'myGroup' 
version '1.0-SNAPSHOT' 

apply plugin: 'java' 
apply plugin: 'idea' 
apply plugin: 'maven' 

sourceCompatibility = 1.8 

buildscript { 
    repositories { 
     jcenter() 
    } 

    dependencies { 

     classpath 'io.spring.gradle:dependency-management-plugin:0.5.6.RELEASE' 
     classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE' 
     classpath 'com.bmuschko:gradle-tomcat-plugin:2.0' 

    } 

} 

repositories { 
    jcenter() 
} 



dependencies { 
    testCompile group: 'junit', name: 'junit', version: '4.11' 
    testCompile 'org.mockito:mockito-all:1.8.4' 
    compile 'ch.qos.logback:logback-classic:1.1.7' 
} 



task wrapper(type: Wrapper) { 
    gradleVersion = '2.12' 
} 
} 

該模塊搖籃腳本:

apply plugin: "io.spring.dependency-management" 
apply plugin: "spring-boot" 

repositories { 
jcenter() 
} 

dependencyManagement { 
imports { 
    mavenBom 'io.spring.platform:platform-bom:2.0.3.RELEASE' 
} 
} 
dependencies { 
    compile "org.springframework:spring-web" 
    compile "org.springframework.boot:spring-boot-starter-web" 
    compile "org.springframework.boot:spring-boot-starter-actuator" 
    compile 'com.netflix.feign:feign-okhttp:8.16.2' 
} 

回答

1

你需要確保bootRepackage任務install之前運行。要做到這一點粗的方法是在命令行上同時指定:

./gradlew bootRepackage install 

更好的辦法是配置install任務依賴於bootRepackage任務。您可以通過添加這樣做以下到您build.gradle

install { 
    dependsOn bootRepackage 
} 

有了這個配置,當你運行install搖籃就會自動運行bootRepackage。例如:

$ ./gradlew install 
:compileJava UP-TO-DATE 
:processResources UP-TO-DATE 
:classes UP-TO-DATE 
:findMainClass 
:jar 
:bootRepackage 
:install 

BUILD SUCCESSFUL 

Total time: 5.487 secs 
+0

謝謝,我會嘗試在週日 –

+0

它的工作,但語法是有點不同:install.dependsOn { bootRepackage } –