【问题标题】:Gradle - create Jar from Spring Boot project which consist only of .class filesGradle - 从仅包含 .class 文件的 Spring Boot 项目创建 Jar
【发布时间】:2017-12-15 01:18:15
【问题描述】:

我对 Gradle 有疑问。我有一个简单的 spring boot 项目,我想只用里面的包和 .class 文件来 jar 它。我现在收到的是 3 个文件夹 BOOT-INF、META-INF 和 org.springframework.boot.loader。

【问题讨论】:

  • 它应该是一个可运行的 jar 吗?还是图书馆?
  • @Strelok 库。
  • 然后从你的项目中实际删除org.springframework.boot gradle 插件。
  • 喜欢应用插件:'org.springframework.boot' 和依赖部分的类路径?
  • 查看我关于如何使用 spring boot 但不使用其插件的答案,该插件仅用于构建实际应用程序与库。

标签: spring-boot gradle


【解决方案1】:

您需要删除 gradle 插件。它仅在您想构建一个 Spring Boot 应用程序时才有用。

这里是如何构建一个库(但仍然使用spring boot):

buildscript {
  ext {
    springBootVersion = '1.5.2.RELEASE'
    dependencyManagementPluginVersion = '1.0.1.RELEASE'
  }

  repositories {
    mavenLocal()
    mavenCentral()
  }

  dependencies {
    classpath "io.spring.gradle:dependency-management-plugin:$dependencyManagementPluginVersion"
  }
}

repositories {
    mavenLocal()
    mavenCentral()
}

apply plugin: 'io.spring.dependency-management'

dependencyManagement {
  imports {
    mavenBom "org.springframework.boot:spring-boot-starter-parent:$springBootVersion"
  }
}

dependencies {
  compile 'org.springframework.boot:spring-boot-starter-web' // no need to specify version
}

【讨论】:

    【解决方案2】:

    如果您正在创建 Spring-boot 项目的 .jar 工件并希望将其用作另一个应用程序中的外部依赖项(例如,引用其中的 main 类),您可以将其添加到您的 Boot应用程序的build.gradle 文件以及 .jar 发布配置:

    bootRepackage  {
        classifier = 'exec'
    }
    

    (来源:https://github.com/spring-projects/spring-boot/commit/6565ff616a827c22b4235d8ce2fb9a94eb4ad4c8?short_path=1c5002a#diff-1c5002aface9c68d53c46740b5f095e5

    【讨论】:

      猜你喜欢
      • 2017-11-03
      • 1970-01-01
      • 1970-01-01
      • 2020-01-16
      • 2016-06-05
      • 2018-02-23
      • 2017-10-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多