在網(wǎng)上搜了很多資料躲撰,是這么打包的
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 依賴,然后全部放到j(luò)ar包中击费,這可能引發(fā)了類加載器的問題拢蛋,因為這會打亂原本應(yīng)該由各個不同類加載器負責加載的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'
}
}