【问题标题】:Gradle + Spring Boot can't handle jars with more than 65535 filesGradle + Spring Boot 无法处理超过 65535 个文件的 jar
【发布时间】:2017-07-12 02:46:47
【问题描述】:

使用zip64 true 不会创建可用的 jar 文件。尽管 Manifest.mf 的文件、结构和位置与以前的构建版本完全相同,但它无法在该 jar 中找到主类。

真正的问题是:我的最终构建中不需要 sonarqube 或 gatling(这些与测试相关),但 AFAIK 无法排除插件。

“fatJar”任务用于创建 jar。

非常感谢任何形式的帮助。

plugins {
    id "org.sonarqube" version "2.2.1"
    id "com.github.lkishalmi.gatling" version "0.4.1"
}

// Run in terminal with "gradle sonarqube"
sonarqube {
    properties {
        property "sonar.projectName", "asd"
        property "sonar.projectKey", "org.sonarqube:java-gradle-simple"
        property "sonar.host.url", "http://asd"
        property "sonar.login", "asd"
        property "sonar.password", "asd"
    }
}

// Run in terminal with "gradle gatlingrun", start the application before.
gatling {
    logLevel 'ERROR'
    simulations = {
        include "**/LoginAndSync.scala"
    }
}

group 'asd'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

task fatJar(type: Jar) {
    //zip64 true
    manifest {
        attributes 'Implementation-Title': 'Gradle Jar File Example',
                'Implementation-Version': version,
                'Main-Class': 'application.Asd'
    }
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}

dependencies {
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.4.1.RELEASE'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.4.1.RELEASE'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version: '1.4.1.RELEASE'
    compile group: 'org.springframework', name: 'spring-orm', version: '4.3.3.RELEASE'
    compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.5'
    compile group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.11.80'
    compile group: 'io.gatling.highcharts', name: 'gatling-charts-highcharts', version: '2.2.3'

    testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '1.4.1.RELEASE'
    testCompile group: 'com.h2database', name: 'h2', version: '1.4.193'
    testCompile group: 'junit', name: 'junit', version: '4.12'
    testCompile group: 'org.springframework.security', name: 'spring-security-test', version: '4.0.0.RELEASE'
}

这是我得到的异常:

xecution failed for task ':fatJar'.
> archive contains more than 65535 entries.

  To build this archive, please enable the zip64 extension.
  See: https://docs.gradle.org/3.3/dsl/org.gradle.api.tasks.bundling.Zip.html#org.gradle.api.tasks.bundling.Zip:zip64

【问题讨论】:

  • 你在使用 Spring Boot 为什么要创建自己的 fat-jar?使用 Spring Boot 插件并删除您自己的 fat-jar 任务。
  • @M.Deinum 我们还使用 gradle 运行测试。全部在 docker 脚本中。我不确定,但我认为“在命令行上”这样做不是一件容易的事?
  • 这与使用 spring boot 插件有什么关系。按照建议,删除 fat jar 任务并使用适当的插件。
  • @M.Deinum 我做到了,它奏效了。谢谢! :)

标签: gradle spring-boot jar build.gradle executable-jar


【解决方案1】:

感谢 M.Deinum,我采用了一种新方法:

我在build.gradle中添加了spring-boot作为插件

plugins {
    id 'org.springframework.boot' version '1.5.1.RELEASE'
}

现在可以在控制台中使用gradle build 来获取运行中的jar,可以在./build/libs/ 中找到。

【讨论】:

    猜你喜欢
    • 2018-11-11
    • 2016-02-08
    • 2021-11-08
    • 2016-04-22
    • 2021-03-05
    • 2018-06-10
    • 1970-01-01
    • 1970-01-01
    • 2019-05-31
    相关资源
    最近更新 更多