所以我认为您正在寻找两种配置。
apply plugin: 'groovy'
repositories {
jcenter()
}
dependencies {
compile localGroovy()
compile 'org.slf4j:slf4j-api:1.7.21'
compileOnly group: 'com.google.guava', name: 'guava', version: '20.0'
testCompile 'junit:junit:4.12'
}
task fatJar(type: Jar) {
from sourceSets.main.output, configurations.compile
baseName = "$project.name-fat"
}
jar.dependsOn fatJar
现在我们可以为我们有兴趣部署到的每个上下文创建一个 jar
$ ./gradlew clean build
Configuration on demand is an incubating feature.
:clean
:compileJava UP-TO-DATE
:compileGroovy
:processResources UP-TO-DATE
:classes
:fatJar
:jar
:assemble
:compileTestJava UP-TO-DATE
:compileTestGroovy UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
BUILD SUCCESSFUL
Total time: 4.997 secs
现在让我们验证我们有一个胖罐子
$ unzip build/libs/q40727142-fat.jar -d build/libs/included
Archive: build/libs/q40727142-fat.jar
creating: build/libs/included/META-INF/
inflating: build/libs/included/META-INF/MANIFEST.MF
creating: build/libs/included/com/
creating: build/libs/included/com/jbirdvegas/
creating: build/libs/included/com/jbirdvegas/q40727142/
inflating: build/libs/included/com/jbirdvegas/q40727142/Hello.class
inflating: build/libs/included/groovy-all-2.4.7.jar
inflating: build/libs/included/slf4j-api-1.7.21.jar
并且让我们验证原始配置中没有我们期望提供的 jars。
$ unzip build/libs/q40727142.jar -d build/libs/notIncluded
Archive: build/libs/q40727142.jar
creating: build/libs/notIncluded/META-INF/
inflating: build/libs/notIncluded/META-INF/MANIFEST.MF
creating: build/libs/notIncluded/com/
creating: build/libs/notIncluded/com/jbirdvegas/
creating: build/libs/notIncluded/com/jbirdvegas/q40727142/
inflating: build/libs/notIncluded/com/jbirdvegas/q40727142/Hello.class