如何从同一来源创建多个罐子,但每个罐子的主要类别不同?

时间:2016-06-08 04:06:05

标签: java gradle

这是我的build.gradle的样子。我希望能够从同一个项目创建多个罐子,但每个罐子的主要类别不同? 最后的linkToBin函数将是最后一个要执行的函数,它应该通过执行configurations.testRuntime.allArtifacts.files.forEach来收集所有的jar。无论如何,最大的问题是如何从同一来源创建多个罐子,但每个罐子的主要类别不同?任何帮助都会很棒

apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'maven'

group 'com.hello'
version '1.0'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
    flatDir {
        dirs '/usr/local/hello/lib'
    }
}

dependencies {
    compile 'commons-cli:commons-cli:1.3.1'
    compile 'org.slf4j:slf4j-log4j12:1.7.12'
    testCompile group: 'junit', name: 'junit', version: '4.11'
    compile "com.sparkjava:spark-core:2.5"
    compile group: 'com.google.code.gson', name: 'gson', version: '2.6.2'
   compile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.8.11.2'
   compile project(':anchor_service_api_thrift')
}

jar {
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    from sourceSets.test.output
    manifest {
        attributes 'Main-Class': 'com.hello.echoserver.AnchorEchoServer'
    }
    exclude 'META-INF/.RSA', 'META-INF/.SF','META-INF/*.DSA'
}

task (anchorHttpServerJar, dependsOn: 'classes', type: Jar) {
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    from sourceSets.test.output
    archivesBaseName = 'anchor_echo_http_server'
    version = '1.0-SNAPSHOT'
    manifest {
        attributes ('Main-Class': 'com.hello.httpserver.AnchorHttpServer')
    }
    exclude 'META-INF/.RSA', 'META-INF/.SF','META-INF/*.DSA'
}

artifacts {
   archives anchorHttpServerJar
}

build.dependsOn(linkToBin)

1 个答案:

答案 0 :(得分:0)

您可以使用Application Plugin

build.gradle 文件中,只需添加以下内容:

apply plugin: 'application'
mainClassName = "you.main.class.Program"