java如何在带有Gradle的JAR中包含单个依赖项?
我从Gradle开始,我想知道如何将一个依赖项(在我的例子中是TeamSpeak API)包含到我的JAR中,以便它在运行时可用
这是我身体的一部分。格拉德尔:
apply plugin: 'java'
compileJava {
sourceCompatibility = '1.8'
options.encoding = 'UTF-8'
}
jar {
manifest {
attributes 'Class-Path': '.......'
}
from {
* What should I put here ? *
}
}
dependencies {
compile group: 'org.hibernate', name: 'hibernate-core', version: '4.3.7.Final'
compile group: 'org.spigotmc', name: 'spigot', version: '1.8-R0.1-RELEASE'
// Many other dependencies, all available at runtime...
// This one isn't. So I need to include it into my JAR :
compile group: 'com.github.theholywaffle', name: 'teamspeak3-api', version: '+'
}
谢谢你的帮助:)
# 1 楼答案
最简单的方法是从要包含的依赖项的单独配置开始。我知道您只询问了一个jar,但是如果您在新配置中添加更多依赖项,这个解决方案就会起作用。Maven对这类东西有一个众所周知的名字叫做
provided
,所以我们将使用它使用
provided
作为配置的名称也很重要,因为当发布jar时,provided
配置中的任何依赖项都将在POM中显示为provided
。与JAR一起发布的xml。Maven依赖项解析程序不会下拉provided
依赖项,jar的用户不会在类路径上得到类的重复副本。见Maven Dependency Scopes