gradle打jar

在网上搜了很多资料,是这么打包的

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'
    }
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容