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"

相关推荐
Terio_my15 分钟前
Spring Boot 热部署配置与禁用
java·spring boot·后端
青云交1 小时前
Java 大视界 -- Java 大数据在智能安防视频监控系统中的视频语义理解与智能检索进阶
java·深度学习·监控系统·行为识别·智能安防·智能检索·视频语义理解
!chen1 小时前
如何在新的Spring Boot项目中关闭Spring Security?
java·spring·jar
我是华为OD~HR~栗栗呀1 小时前
Java面经(22届考研-华oD)
java·后端·python·华为od·华为
z晨晨2 小时前
互联网大厂Java求职面试实战:Spring Boot与微服务场景深度解析
java·spring boot·redis·微服务·kafka·spring security·电商
练习时长一年3 小时前
Bean后处理器
java·服务器·前端
野犬寒鸦3 小时前
从零起步学习Redis || 第五章:利用Redis构造分布式全局唯一ID
java·服务器·数据库·redis·分布式·后端·缓存
吹晚风吧3 小时前
SSE是什么?SSE解决什么问题?在什么场景使用SSE?
java·springboot·sse
Terio_my3 小时前
IDEA自动构建与热部署配置
java·ide·intellij-idea
数智顾问4 小时前
Java坐标转换的多元实现路径:在线调用、百度与高德地图API集成及纯Java代码实现——纯Java代码实现与数学模型深度剖析
java·开发语言