如何将测试类包含到shadowJar中?

我正在使用shadow Gradle插件来构建JAR,其中包含所有引用的jar.

在我的build.gradle中我只有

apply plugin: "com.github.johnrengelman.shadow"

jar {
    manifest {
        attributes 'Main-Class': 'MYCLASS'
    }

}

与此有关.我不知道,它是如何知道的,建造什么,但它有效.

现在,是否有可能包括测试类?

最佳答案 来自官方文档
https://imperceptiblethoughts.com/shadow/custom-tasks/

Shadowing Test Sources and Dependencies


import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
task testJar(type: ShadowJar) {
classifier = 'tests'
from sourceSets.test.output
configurations = [project.configurations.testRuntime]
}

The code snippet above will geneated a shadowed JAR contain both the main and test sources as well as all runtime and testRuntime dependencies. The file is output to build/libs/–tests.jar.

点赞