我正在使用shadow Gradle插件来构建JAR,其中包含所有引用的jar。
在build.gradle
我只有
apply plugin: "com.github.johnrengelman.shadow"
和
jar {
manifest {
attributes 'Main-Class': 'MYCLASS'
}
}
与此相关。我不知道,它是如何知道的,建造什么,但它有效。
现在,是否有可能包含测试类?
答案 0 :(得分:1)
来自官方文档https://imperceptiblethoughts.com/shadow/custom-tasks/
阴影测试源和依赖
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar task testJar(type: ShadowJar) { classifier = 'tests' from sourceSets.test.output configurations = [project.configurations.testRuntime] }
上面的代码片段将生成一个带阴影的JAR,它包含主要和测试源以及所有运行时和testRuntime依赖项。该文件输出到build / libs / - tests.jar。
答案 1 :(得分:0)
官方文档似乎与插件的最新 (v7.0.0) 版本过时了。使用这个版本和最新版本的gradle(7.0),我这样做:
task testJar(type: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) {
archiveClassifier.set("alltests")
from sourceSets.main.output, sourceSets.test.output
configurations = [project.configurations.testRuntimeClasspath]
}
文档中的 from
子句和“configurations”子句都错误。
sourceSets.main.output
project.configurations.testRuntime
没有按照文档工作,它告诉我 testImplementation' is not allowed as it is defined as 'canBeResolved=false