没有可执行jar的Spring Boot 2 Gradle插件

问题描述 投票:2回答:3

如何配置Spring Boot Gradle插件2以禁用Gradle Script Kotlin中的Boot分发。

我想要的分发是一个汇编包zip,包含lib文件夹中的所有依赖项(和jar)。

我启用了Jar任务并禁用了bootJar任务。

我的构建文件https://github.com/Skatteetaten/mokey/blob/825a81f20c21a2220876a09ebf7f01fe7c61f2fd/build.gradle.kts的当前来源

请注意,极光skatteetaten gradle插件添加了分发机制。 https://github.com/Skatteetaten/aurora-gradle-plugin

spring-boot gradle kotlin spring-boot-gradle-plugin
3个回答
6
投票

配置应用程序插件后,Spring Boot会创建一个包含应用程序包作为胖罐的附加分发。默认分发保持不变,您应该能够在不禁用Boot分发的情况下使用它。

默认分发依赖于标准的jar任务。默认情况下,Spring Boot的插件禁用此任务,因为假设您将要使用bootJar生成的胖jar。如果不是这样,你可以像这样重新启用jar:

jar {
    enabled = true
}

有了这个改变,你可以运行distZip任务:

$: ./gradlew clean distZip --console=plain
:clean
:bootBuildInfo
:compileJava
:processResources
:classes
:jar
:startScripts
:distZip

BUILD SUCCESSFUL in 1s
7 actionable tasks: 7 executed

它将创建一个zip,将应用程序及其所有依赖项打包为分发的lib目录中的单独jar。

$: unzip -l build/distributions/application-distribution-0.0.1-SNAPSHOT.zip
Archive:  build/distributions/application-distribution-0.0.1-SNAPSHOT.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  03-19-2018 07:31   application-distribution-0.0.1-SNAPSHOT/
        0  03-19-2018 07:31   application-distribution-0.0.1-SNAPSHOT/lib/
     1860  03-19-2018 07:31   application-distribution-0.0.1-SNAPSHOT/lib/application-distribution-0.0.1-SNAPSHOT.jar
      588  03-01-2018 05:24   application-distribution-0.0.1-SNAPSHOT/lib/spring-boot-starter-web-2.0.0.RELEASE.jar
      645  03-01-2018 05:24   application-distribution-0.0.1-SNAPSHOT/lib/spring-boot-starter-json-2.0.0.RELEASE.jar
      592  03-01-2018 05:23   application-distribution-0.0.1-SNAPSHOT/lib/spring-boot-starter-2.0.0.RELEASE.jar
      590  03-01-2018 05:24   application-distribution-0.0.1-SNAPSHOT/lib/spring-boot-starter-tomcat-2.0.0.RELEASE.jar
  1117582  01-08-2018 11:43   application-distribution-0.0.1-SNAPSHOT/lib/hibernate-validator-6.0.7.Final.jar
   782155  02-19-2018 10:08   application-distribution-0.0.1-SNAPSHOT/lib/spring-webmvc-5.0.4.RELEASE.jar
  1244848  02-19-2018 10:08   application-distribution-0.0.1-SNAPSHOT/lib/spring-web-5.0.4.RELEASE.jar
  1145432  03-01-2018 05:23   application-distribution-0.0.1-SNAPSHOT/lib/spring-boot-autoconfigure-2.0.0.RELEASE.jar
   922427  03-01-2018 05:23   application-distribution-0.0.1-SNAPSHOT/lib/spring-boot-2.0.0.RELEASE.jar
      613  03-01-2018 05:23   application-distribution-0.0.1-SNAPSHOT/lib/spring-boot-starter-logging-2.0.0.RELEASE.jar
    26586  03-01-2018 05:23   application-distribution-0.0.1-SNAPSHOT/lib/javax.annotation-api-1.3.2.jar
  1079064  02-19-2018 10:08   application-distribution-0.0.1-SNAPSHOT/lib/spring-context-5.0.4.RELEASE.jar
   360034  02-19-2018 10:08   application-distribution-0.0.1-SNAPSHOT/lib/spring-aop-5.0.4.RELEASE.jar
   654022  02-19-2018 10:08   application-distribution-0.0.1-SNAPSHOT/lib/spring-beans-5.0.4.RELEASE.jar
   263410  02-19-2018 10:08   application-distribution-0.0.1-SNAPSHOT/lib/spring-expression-5.0.4.RELEASE.jar
  1216414  02-19-2018 10:08   application-distribution-0.0.1-SNAPSHOT/lib/spring-core-5.0.4.RELEASE.jar
   297518  10-24-2017 03:28   application-distribution-0.0.1-SNAPSHOT/lib/snakeyaml-1.19.jar
    33391  01-30-2018 09:16   application-distribution-0.0.1-SNAPSHOT/lib/jackson-datatype-jdk8-2.9.4.jar
    98261  01-30-2018 09:16   application-distribution-0.0.1-SNAPSHOT/lib/jackson-datatype-jsr310-2.9.4.jar
     8643  01-30-2018 09:16   application-distribution-0.0.1-SNAPSHOT/lib/jackson-module-parameter-names-2.9.4.jar
  1345154  01-30-2018 09:16   application-distribution-0.0.1-SNAPSHOT/lib/jackson-databind-2.9.4.jar
   257309  02-14-2018 08:07   application-distribution-0.0.1-SNAPSHOT/lib/tomcat-embed-websocket-8.5.28.jar
  3109223  02-14-2018 08:07   application-distribution-0.0.1-SNAPSHOT/lib/tomcat-embed-core-8.5.28.jar
   240498  02-14-2018 08:07   application-distribution-0.0.1-SNAPSHOT/lib/tomcat-embed-el-8.5.28.jar
    93107  01-08-2018 11:43   application-distribution-0.0.1-SNAPSHOT/lib/validation-api-2.0.1.Final.jar
    66469  02-20-2018 12:53   application-distribution-0.0.1-SNAPSHOT/lib/jboss-logging-3.3.2.Final.jar
    65100  09-19-2017 07:31   application-distribution-0.0.1-SNAPSHOT/lib/classmate-1.3.4.jar
   290339  06-16-2017 04:40   application-distribution-0.0.1-SNAPSHOT/lib/logback-classic-1.2.3.jar
    17519  11-28-2017 08:42   application-distribution-0.0.1-SNAPSHOT/lib/log4j-to-slf4j-2.10.0.jar
     4596  03-27-2017 12:22   application-distribution-0.0.1-SNAPSHOT/lib/jul-to-slf4j-1.7.25.jar
    15836  02-19-2018 10:08   application-distribution-0.0.1-SNAPSHOT/lib/spring-jcl-5.0.4.RELEASE.jar
    66519  08-03-2017 05:28   application-distribution-0.0.1-SNAPSHOT/lib/jackson-annotations-2.9.0.jar
   320923  01-30-2018 09:16   application-distribution-0.0.1-SNAPSHOT/lib/jackson-core-2.9.4.jar
   471901  06-16-2017 04:40   application-distribution-0.0.1-SNAPSHOT/lib/logback-core-1.2.3.jar
    41203  03-27-2017 12:22   application-distribution-0.0.1-SNAPSHOT/lib/slf4j-api-1.7.25.jar
   255485  11-28-2017 08:42   application-distribution-0.0.1-SNAPSHOT/lib/log4j-api-2.10.0.jar
        0  03-19-2018 07:31   application-distribution-0.0.1-SNAPSHOT/bin/
     7002  03-19-2018 07:31   application-distribution-0.0.1-SNAPSHOT/bin/application-distribution
     4042  03-19-2018 07:31   application-distribution-0.0.1-SNAPSHOT/bin/application-distribution.bat
---------                     -------
 15926900                     42 files

4
投票

在spring-boot 2中,gradle插件重新配置构建,以便在应用应用程序和maven插件时在uploadArchives任务中包含引导tar和zip分发。

从我的问题可以看出,你想要一个包含所有jar文件的zip文件,类似于应用程序插件创建的,但是想要排除spring boot插件添加的所有“额外”?如果是这种情况,那么告诉gradle这样做是一件简单的事情;

apply plugin: 'application'
apply plugin: 'maven'

jar.enabled = true
[bootJar, distTar, bootDistTar, bootDistZip]*.enabled = false
configurations.archives.artifacts.removeIf { !it.archiveTask.is(distZip) }

这很时髦,但希望你能够在你的kotlin文件中以类似的方式应用它。


0
投票

这项工作对我来说(禁用spring-boot bootJar任务,并启用jar)

apply plugin: 'java'
bootJar {
  enabled = false
}
© www.soinside.com 2019 - 2024. All rights reserved.