无法使用gradle将spring-boot-fat jar安装到maven存储库中



我用gradle编写了一个spring-boot应用程序,它运行正常。

我使用bootRepackage构建了一个胖罐子,我添加了maven插件,这样我就可以安装罐子了。

问题是我无法将fat jar安装到maven存储库中。

  1. "bootRepackage"构建胖罐子文件
  2. 安装依赖于"jar"阶段,因此它构建了一个覆盖胖jar文件的瘦jar
  3. 薄罐子被复制到存储库

这是我为基础项目编写的渐变脚本,请注意,我仍在尝试安装到我的本地存储库(我们是一家新公司,仍在构建远程存储库)

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

您需要确保bootRepackage任务在install之前运行。一种粗略的方法是在命令行上指定两者:

./gradlew bootRepackage install

更好的方法是将install任务配置为依赖于bootRepackage任务。您可以通过在build.gradle中添加以下内容来完成此操作:

install {
    dependsOn bootRepackage
}

有了此配置,Gradle将在您运行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

最新更新