[英]Gradle jar does not include Guava Preconditions
我的項目有以下build.gradle文件
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.guava:guava:23.6-jre';
testCompile group: 'junit', name: 'junit', version: '4.12'
}
jar {
manifest {
attributes 'Main-Class': 'Runner.ClientRunner'
}
}
但是,當我運行“ gradle jar”並嘗試運行給定的jar時,出現錯誤:
java.lang.NoClassDefFoundError: com/google/common/base/Preconditions
我似乎無法在這里弄清楚我做錯了什么,番石榴包含在gradle的依賴項中,否則jar文件似乎可以很好地構建(否則,它只會在到達依賴番石榴的第一類時崩潰)。 任何幫助表示贊賞。 如果有幫助,我可以通過IntelliJ進行。
我使用https://discuss.gradle.org/t/how-to-include-dependencies-in-jar/19571中的解決方案解決了我的問題
我的build.gradle現在看起來像
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
configurations {
// configuration that holds jars to include in the jar
extraLibs
}
dependencies {
compile 'com.google.guava:guava:23.6-jre';
extraLibs group: 'com.google.guava', name: 'guava', version: '23.6-jre'
testCompile group: 'junit', name: 'junit', version: '4.12'
configurations.compile.extendsFrom(configurations.extraLibs)
}
jar {
manifest {
attributes 'Main-Class': 'Runner.ClientRunner'
}
from {
configurations.extraLibs.collect { it.isDirectory() ? it : zipTree(it) }
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.