【问题标题】:Spring Boot plugin doesn't add lib folder in jarSpring Boot 插件不会在 jar 中添加 lib 文件夹
【发布时间】:2018-09-07 17:47:39
【问题描述】:

我有以下build.gradle

group 'as'
version '1.0'

buildscript {
    ext {
        springVersion = '5.0.4.RELEASE'
        springBootVersion = '1.5.6.RELEASE'
        springJPAVersion = '2.0.5.RELEASE'
        javaxVersion = '1.0.2'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'org.springframework.boot'

jar {
    baseName = 'reports'
    version =  '0.0.1'

    manifest {
        attributes 'Implementation-Title': baseName,
                'Implementation-Version': version
    }

    from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

repositories {
    jcenter()
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/milestone" }
}

dependencies {
    implementation "org.springframework.boot:spring-boot-starter-web:${springBootVersion}"
    implementation "org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}"
    implementation "org.springframework.data:spring-data-jpa:${springJPAVersion}"
    implementation "javax.persistence:persistence-api:${javaxVersion}"
    implementation "mysql:mysql-connector-java:5.1.43"

    testImplementation group: 'junit', name: 'junit', version: '4.11'
}

而 gradle 创建具有以下结构的 jar:

  • 引导-INF
  • 元信息
  • 组织

但是好像结构应该是这样的:

  • 引导-INF
  • 元信息
  • 组织

带有包含依赖项的 lib 文件夹,因为现在启动后出现错误:

异常...

引起:java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication at com.as.reports.Application.main(Application.java:12)

【问题讨论】:

    标签: spring-boot gradle jar


    【解决方案1】:

    所以我知道这个答案可能为时已晚,无法帮助您,但我在尝试解决 exact 同样的问题时偶然发现了这个问题,并提醒了this

    经过半天的反复试验,我找到了解决方案,所以希望我可以避免其他人发现这个没有答案的问题的痛苦。

    问题在于在依赖项中使用 implementation 关键字。 1.x Spring Boot Gradle 插件似乎没有将该关键字识别为重新打包胖 jar 所需的依赖项。如果您将它们改回旧的 compile 关键字,您应该获得必要的 lib 文件夹。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-13
      • 2014-04-25
      • 2020-11-03
      • 1970-01-01
      • 2017-10-23
      相关资源
      最近更新 更多