Gradle 将外部jar绑定到输出jar文件的依赖项中
我有以下Gradle 将外部jar绑定到输出jar文件的依赖项中,gradle,Gradle,我有以下build.gradle文件。我的一个依赖项是jsonsimple。然而, 当我创建jar文件中未包含的jarHttpSnapClient时 apply plugin: 'java' apply plugin: 'application' apply plugin: 'groovy' mainClassName = 'com.sunsystem.HttpSnapClient.SnapClient' repositories { mavenLo
build.gradle
文件。我的一个依赖项是jsonsimple
。然而,
当我创建jar文件中未包含的jarHttpSnapClient
时
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'groovy'
mainClassName = 'com.sunsystem.HttpSnapClient.SnapClient'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile "com.googlecode.json-simple:json-simple:1.1.1"
testCompile "org.codehaus.groovy:groovy:2.3.3"
testCompile "org.spockframework:spock-core:0.7-groovy-2.0"
}
jar {
baseName = 'HttpSnapclient'
version ='1.0.0'
}
task wrapper(type: Wrapper) {
gradleVersion = '1.12'
}
我想将json simple.jar
捆绑到我的HttpSnapClient.jar
中,这样我的应用程序将使用这个HttpSnapClient.jar
就已经包含了json simple.jar
当我运行以下命令jar tvf HttpSnapclient-1.0.0.jar时
0 Mon Jun 30 14:37:56 ICT 2014 META-INF/
25 Mon Jun 30 14:37:56 ICT 2014 META-INF/MANIFEST.MF
294 Mon Jun 30 14:37:56 ICT 2014 WebServiceResponseCodes.class
0 Mon Jun 30 14:37:56 ICT 2014 com/
0 Mon Jun 30 14:37:56 ICT 2014 com/sunsystem/
0 Mon Jun 30 14:37:56 ICT 2014 com/sunsystem/HttpSnapClient/
5965 Mon Jun 30 14:37:56 ICT 2014 com/sunsystem/HttpSnapClient/SnapClient.class
没有包含json simple,因此任何使用此HttpSnapClient的应用程序都会在查找未包含的json simple时失败
当我运行时,我会得到以下信息:gradle依赖项
:dependencies
------------------------------------------------------------
Root project
------------------------------------------------------------
archives - Configuration for archive artifacts.
No dependencies
compile - Compile classpath for source set 'main'.
\--- com.googlecode.json-simple:json-simple:1.1.1
\--- junit:junit:4.10
\--- org.hamcrest:hamcrest-core:1.1
default - Configuration for default artifacts.
\--- com.googlecode.json-simple:json-simple:1.1.1
\--- junit:junit:4.10
\--- org.hamcrest:hamcrest-core:1.1
提前感谢您的建议。是您可能正在寻找的插件。默认情况下,依赖项不包含在jar文件中。似乎您正在运行gradle build而不是gradle distZip或gradle distTar,后者将所有内容捆绑到zip或tar中。也许你对@Opal建议的解决方案更感兴趣。应用程序插件将创建一个发行版,其中包含StartupScript的bin文件夹和所有JAR的lib 是的,我在运行gradle build。但是,我不想将所有内容都打包到tar归档中。我想做的是得到一个罐子。因为我将有许多外部jar(目前我只有json simple)。我想将所有这些绑定到一个jar中,在我的例子中,这个jar将被称为HttpSnapclient.jar。谢谢。猜猜是这样的:那么一些可供选择的替代方案将是提到的FAT jar,或者像WOR/JAR任务一样处理这个:谢谢你的信息。我明天第一件事就去看看。
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'groovy'
mainClassName = 'com.sunsystem.HttpSnapClient.SnapClient'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile "com.googlecode.json-simple:json-simple:1.1.1"
testCompile "org.codehaus.groovy:groovy:2.3.3"
testCompile "org.spockframework:spock-core:0.7-groovy-2.0"
}
jar {
baseName = 'HttpSnapclient'
version ='1.0.0'
}
task wrapper(type: Wrapper) {
gradleVersion = '1.12'
}