注: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包

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐