在网上搜了很多资料,是这么打包的
jar {
    manifestContentCharset 'utf-8'
    metadataCharset 'utf-8'
    manifest {
        attributes 'Class-Path': configurations.runtime.files.collect { "lib/$it.name" }.join(' ')
        attributes "Manifest-Version": 1.0,
                'Main-Class': 'MainTest'
    }
    from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
}
zipTree 来收集所有 runtimeClasspath 依赖,然后全部放到jar包中,这可能引发了类加载器的问题,因为这会打乱原本应该由各个不同类加载器负责加载的jar包。
更正后的用法,我用的gradle版本是6.1.0,与之匹配是5.1.0。
plugins {
    id 'java'
    id 'com.github.johnrengelman.shadow' version '5.1.0'  // Check for the latest version
}
// Configure the shadowJar task
shadowJar {
    archiveBaseName.set('SelenideDemo')
    archiveVersion.set('1.0-SNAPSHOT')
    archiveClassifier.set('')
    manifest {
        attributes 'Main-Class': 'TokenGetTest'
    }
}