gradle打包web jar_如何使用Gradle打包一个可运行的jar

在使用Gradle打包成一个可运行的Jar包的时候,需要把编译时依赖的库也打包进去,因此要搞清楚打包时如何才能将库文件打包进去。

对于implementation引入的库,则需要如下的语句:

from {

configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }

}

对于testImplementation引入的库,则需要如下的语句:

from {

configurations.testRuntimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }

}

我们只需要打包运行时的依赖包即可,则完整build.gradle如下:

plugins {

id 'java'

id 'org.jetbrains.kotlin.jvm' version '1.3.21'

}

group 'com.zhuyanbin'

version '1.0.0'

sourceCompatibility = 1.8

repositories {

mavenCentral()

}

jar {

manifest {

attributes 'Implementation-Title' : 'DropBox-Backup-Service'

attributes 'Manifest-Version': '1.0.0'

attributes 'Main-Class': 'com.zhuyanbin.dropbox.AppKt'

}

from {

configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }

}

}

dependencies {

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"

implementation 'com.dropbox.core:dropbox-core-sdk:3.0.10'

implementation 'commons-configuration:commons-configuration:1.9'

testImplementation group: 'org.junit.platform', name: 'junit-platform-launcher', version:'1.4.0'

testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version:'5.4.0'

testImplementation group: 'org.junit.vintage', name: 'junit-vintage-engine', version:'5.4.0'

}

compileKotlin {

kotlinOptions.jvmTarget = "1.8"

}

compileTestKotlin {

kotlinOptions.jvmTarget = "1.8"

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值