Gradle - 将依赖和资源文件打入jar包

2021-02-03 10:18

阅读:547

标签:number   let   back   assets   打包   ken   one   java   html   

https://www.cnblogs.com/jyx140521/p/6855210.html

用以下build.gradle打包出来的jar包,依赖是分离的:

apply plugin: ‘java‘

dependencies {
    compile ‘commons-codec:commons-codec:1.4‘
    compile ‘commons-logging:commons-logging:1.1.1‘
    compile ‘com.google.code.gson:gson:2.4‘
    compile ‘org.apache.httpcomponents:httpclient:4.3.6‘
    compile ‘com.strategicgains:RestExpress:0.11.2‘
    compile ‘com.fasterxml.jackson.core:jackson-databind:2.6.4‘
    compile ‘com.fasterxml.jackson.core:jackson-core:2.6.4‘
    compile ‘com.fasterxml.jackson.core:jackson-annotations:2.6.4‘
    compile "ch.qos.logback:logback-core:1.1.3"
    compile "ch.qos.logback:logback-classic:1.1.3"
    compile ‘net.kencochrane.raven:raven-logback:6.0.0‘
    compile ‘net.kencochrane.raven:raven:6.0.0‘
    compile "org.slf4j:slf4j-api:1.7.13"
    compile ‘com.rabbitmq:amqp-client:4.1.0‘
    compile ‘org.apache.commons:commons-lang3:3.4‘
    compile ‘commons-net:commons-net:3.4‘
    compile ‘org.zeromq:jeromq:0.3.5‘
    compile fileTree(dir: ‘libs‘, include: [‘*.jar‘])
    compile project(‘:tc-das‘)
    compile project(‘:result-compare‘)
}

jar {
    manifest {
        attributes(
                "Manifest-Version": 1.0,
                "Main-Class": "com.testbird.rio.Main",
                "Class-Path": configurations.compile.collect { "lib/${it.name}" }.join(‘ ‘))
    }
}

将build.gradle修改一下,就能将依赖和资源文件打入jar包了:

apply plugin: ‘java‘

dependencies {
    compile ‘commons-codec:commons-codec:1.4‘
    compile ‘commons-logging:commons-logging:1.1.1‘
    compile ‘com.google.code.gson:gson:2.4‘
    compile ‘org.apache.httpcomponents:httpclient:4.3.6‘
    compile ‘com.strategicgains:RestExpress:0.11.2‘
    compile ‘com.fasterxml.jackson.core:jackson-databind:2.6.4‘
    compile ‘com.fasterxml.jackson.core:jackson-core:2.6.4‘
    compile ‘com.fasterxml.jackson.core:jackson-annotations:2.6.4‘
    compile "ch.qos.logback:logback-core:1.1.3"
    compile "ch.qos.logback:logback-classic:1.1.3"
    compile ‘net.kencochrane.raven:raven-logback:6.0.0‘
    compile ‘net.kencochrane.raven:raven:6.0.0‘
    compile "org.slf4j:slf4j-api:1.7.13"
    compile ‘com.rabbitmq:amqp-client:4.1.0‘
    compile ‘org.apache.commons:commons-lang3:3.4‘
    compile ‘commons-net:commons-net:3.4‘
    compile ‘org.zeromq:jeromq:0.3.5‘
    compile fileTree(dir: ‘libs‘, include: [‘*.jar‘])
    compile project(‘:tc-das‘)
    compile project(‘:result-compare‘)
}

jar {
    manifest {
        attributes(
                "Manifest-Version": 1.0,
                "Main-Class": "com.testbird.rio.Main")
    }
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    into(‘assets‘) {
        from ‘assets‘
    }
}

Gradle - 将依赖和资源文件打入jar包

标签:number   let   back   assets   打包   ken   one   java   html   

原文地址:https://www.cnblogs.com/longchang/p/12803317.html


评论


亲,登录后才可以留言!