Gradle java项目打包可执行jar包并添加依赖jar
# Gradle java项目打包可执行jar包并添加依赖jar注:jar项会被解压,并重新打包到新的完整可执行jar中build.gradle文件如下```gradleplugins {id 'java'id 'application'}group 'xxx.com'version '1.0-SNAPSHOT'sourceCompatibility = 1.8repositories {// 阿
·
注:jar项会被解压,并重新打包到新的完整可执行jar中
build.gradle文件如下
plugins {
id 'java'
id 'application'
}
group 'xxx.com'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
maven {
url 'https://maven.aliyun.com/repository/jcenter'
}
maven {
url 'https://maven.aliyun.com/repository/central'
}
maven {
url 'https://maven.aliyun.com/repository/google'
}
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
implementation 'io.netty:netty-all:4.1.50.Final'
}
jar {
String runtimePath = ''
configurations.runtime. each {runtimePath = runtimePath + " lib//" +it.name} // 本地lib
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } // implementation 相关的引入解压并打包入新的jar中
}
manifest {
attributes 'Main-Class' : 'com.xxx.tcp_server.TcpServer' // 设置启动类路径
attributes 'Class-Path' : runtimePath
}
}
在程序根目录执行命令:
gradle jar
在目录:[ApplictionHome]/out/artifacts下即可查看打完的jar包
更多推荐
已为社区贡献1条内容
所有评论(0)