idea纯java工程使用gradle指定生成jar的Main-Class,idea生成jar

build.gradle核心代码如下:

复制代码
jar {
    manifest {
        attributes "Main-Class": "com.example.sample.Application"
    }
    from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

完整代码如下:

复制代码
group 'com.example.sample'
version '2.1.6'

apply plugin: 'java'

tasks.withType(JavaCompile) {
    options.encoding = "UTF-8"
}

sourceCompatibility = 1.8

repositories {
    maven { url "https://maven.aliyun.com/repository/central" }
    maven { url "https://maven.aliyun.com/repository/jcenter" }
    mavenCentral()
//    jcenter()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.11'

    compile 'org.swinglabs.swingx:swingx-core:1.6.5'
    compile "com.squareup.okhttp3:okhttp:3.14.6"
    compile 'com.alibaba:fastjson:1.2.70'
    compile 'org.quartz-scheduler:quartz:2.3.0'
    compile 'com.google.zxing:core:3.4.0'
    compile 'com.google.zxing:javase:3.4.0'
    compile 'com.google.code.gson:gson:2.8.6'
    compile 'mysql:mysql-connector-java:5.1.39'
    compile "org.apache.commons:commons-lang3:3.6"
    compile "commons-net:commons-net:3.6"
    compile "io.github.willena:sqlite-jdbc:3.33.0.1"
    compile "io.projectreactor.netty:reactor-netty:0.9.9.RELEASE"

    compile "org.apache.commons:commons-compress:1.9"

//  不引入xz依赖会在new SevenZFile的时候报错java.lang.NoClassDefFoundError: org/tukaani/xz/FilterOptions
    compile "org.tukaani:xz:1.9"

    //解压rar5,所需依赖开始
    compile "com.github.axet:java-unrar:1.7.0-8"
    compile "com.github.junrar:junrar:4.0.0"

    compile "net.sf.sevenzipjbinding:sevenzipjbinding:16.02-2.01"
    compile "net.sf.sevenzipjbinding:sevenzipjbinding-all-platforms:16.02-2.01"
    compile "org.apache.commons:commons-compress:1.9"
    compile "org.tukaani:xz:1.5"

    compile "commons-io:commons-io:2.8.0"
    compile "com.aliyun.openservices:aliyun-log:0.6.64"

    compile "org.apache.poi:poi:4.1.0"
    compile "org.apache.poi:poi-ooxml:4.1.0"
    compile "net.lingala.zip4j:zip4j:1.3.2"
}

jar {
    manifest {
        attributes "Main-Class": "com.example.sample.Application"
    }
    from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

双击gradle条目下的tasks--build---assemble就可以生成jar;

生成目录在"项目根目录\build\libs"

相关推荐
XiaoYu1__9 小时前
JavaGUI文件管理系统开发实战:从静态展示到动态交互的演进
java·开发语言
霸道流氓气质9 小时前
MCP(Model Context Protocol)核心概念与Java SDK集成
java·开发语言
敲代码的嘎仔10 小时前
从集群锁失效到异步领券:我用分布式锁 + Redisson + MQ 把领券接口 RT 从 200ms 压到 15ms
java·数据库·redis·分布式·缓存·ai·wpf
步行cgn10 小时前
Spring 的模块体系详解
java·数据库·spring
xcl092510 小时前
智慧健身场馆系统开发实战:从架构设计到核心模块落地指南
java·spring boot
vx-程序开发10 小时前
【计算机毕设】基于Spring Boot的古城景区管理系统88564
java·数据库·spring boot·后端·spring·elasticsearch·课程设计
鹿角片ljp10 小时前
LeetCode 31:下一个排列|右找小,右找大,交换,右反转
java·数据结构·算法
边境悍匪10 小时前
蜗牛学苑 Java 智能体学习 Day40|Vue 工程化与 ElementPlus 思维导图复盘
java·vue.js·学习
霸道流氓气质11 小时前
通义千问 VL & Audio:图像、视频、语音多模态 Java 集成深度解析
java·开发语言·音视频
lemon_sjdk11 小时前
WCPoint、WebPageClient和Accessor类源码
java·安全·webkit·javafx