Gradle CLI 构建在 Spring Boot 的 Jar Writer 上失败

Gradle CLI build fails on JarWriter from SpringBoot

错误信息:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':bootRepackage'.
> MALFORMED

* Try:
Run with --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':bootRepackage'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)

....

Caused by: java.lang.IllegalArgumentException: MALFORMED
        at org.springframework.boot.loader.tools.JarWriter.writeEntries(JarWriter.java:92)
        at org.springframework.boot.loader.tools.Repackager.repackage(Repackager.java:144)

设置:
Java版本:
java 版本“1.8.0_31”
Java(TM) SE 运行时环境(构建 1.8。0_31-b13)
Java HotSpot(TM) 64 位服务器 VM(内部版本 25.31-b07,混合模式)

build.gradle

import org.apache.tools.ant.filters.ReplaceTokens
import java.util.Date

def profile = "PROD";


buildscript {
    ext {
        springBootVersion = '1.0.2.RELEASE' //**have tried with 1.2.4 as well**
    }
    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "http://repo.spring.io/release" }
        maven { url "http://repo.spring.io/milestone" }
        maven { url "http://repo.spring.io/snapshot" }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'

mainClassName = "dk.api.gas.Gas"
compileJava.options.encoding = 'UTF-8'
sourceCompatibility = 1.7
targetCompatibility = 1.7

compileJava.options.encoding = "UTF-8"

jar {
    baseName = 'quotes'
    version =  '1.0.0'
}

repositories {
    mavenCentral()
    maven {
        url "http://repo.springsource.org/libs-snapshot"
    }
    maven {url "http://xxxxx.compute.amazonaws.com/artifactory/gradle/"
        credentials {
            username 'xx'
            password 'xxxx'
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')

    compile("org.springframework.boot:spring-boot-starter-aop:${springBootVersion}")

    compile("com.fasterxml.jackson.core:jackson-databind")
    compile('dk.mobile:fileStorageLib:1.4.0')
            {
                exclude module: 'dk.mobile:common'
            }


    compile('dk.mobile:common:2.0.0')
    compile('dk.mobile:mail:1.0.5')

    compile('dk.mobile:update:1.1.0')
            {
                exclude module: 'dk.mobile:common'
            }
    compile('org.apache.solr:solr-solrj:3.1.0')


    compile('dk.mobile:authentication:1.3.0')
            {
                exclude module: 'dk.mobile:common'
            }

    compile('com.googlecode.charts4j:charts4j:1.3')

    compile('org.apache.poi:poi-ooxml:3.12')
}
def getDate() {
    def date = new Date()
    def formattedDate = date.format('dd.MM.yyy - HH:mm:ss')
    return formattedDate
}



processResources {

    filter ReplaceTokens, tokens: ["AppProfile": profile ]


}



task wrapper(type: Wrapper) {
    gradleVersion = '1.11'
}

我在 Windows 上构建时遇到了同样的问题。 问题是我的文件名称很长,所以它们的路径超过了 256 个字符,导致压缩崩溃和 bootRepackage 失败。

在 Linux 另一方面,我在构建相同的应用程序时没有遇到任何问题。

希望对您有所帮助。

另一个问题可能是您的文件包含非 ascii 字符。

我们遇到了同样的错误,因为一些 class 名称使用了德语变音符号(äöü)。重命名 classes 后问题消失了(在 Windows)。

我在构建Windows.The时遇到了同样的问题,问题是名为recources/statics/images/未命名.png的文件,你不能使用中文字符。