gpt4 book ai didi

java - 如何为每个jar从相同的源但不同的主类创建多个jar?

转载 作者:行者123 更新时间:2023-12-03 03:30:32 24 4
gpt4 key购买 nike

这是我的build.gradle的样子。我想能够从同一个项目创建多个jar,但每个jar的主类不同?
最后的linkToBin函数将是要执行的最后一个函数,它应该通过执行configurations.testRuntime.allArtifacts.files.forEach来收集所有jar。无论如何,最大的问题是如何为每个 jar 从同一来源但不同的主类创建多个 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)

最佳答案

您可以使用Application Plugin

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

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

关于java - 如何为每个jar从相同的源但不同的主类创建多个jar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37693043/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com