Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include test classes into shadowJar?

I am using shadow Gradle plugin to build JAR, containing all referenced jars inside.

In my build.gradle I have only

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

and

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

}

related to that. I don't know, how it knows, what to build, but it works.

Now, is it possible, to include test classes too?

like image 850
Dims Avatar asked Nov 30 '16 19:11

Dims


1 Answers

From the official documentation 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.

like image 86
Eyal Roth Avatar answered Sep 19 '22 18:09

Eyal Roth