Skip to content Skip to sidebar Skip to footer

Compile Jar With Test Classes

How can I compile jar with test classes in android? I am using android gradle plugin 1.3.1: classpath 'com.android.tools.build:gradle:1.3.1' I've tried: task testSourcesJar(type:

Solution 1:

The solution mentioned by Tomek Jurkiewicz for Android + Kotlin looks like this:

task jarTests(type: Jar, dependsOn: "assembleDebugUnitTest") {
    getArchiveClassifier().set('tests')
    from "$buildDir/tmp/kotlin-classes/debugUnitTest"
}

configurations {
    unitTestArtifact
}

artifacts {
    unitTestArtifact jarTests
}

Gradle for project that is going to use dependencies:

testImplementation project(path: ':shared', configuration: 'unitTestArtifact')

Solution 2:

It looks like posting a question here gives some kind of inspiration to resolve the problem... anyway, there's the solution:

task testClassesJar(type: Jar, dependsOn: 'compileReleaseUnitTestSources') {
    from 'build/intermediates/classes/test/release'
}

configurations {
    tests
}

artifacts {
    tests testClassesJar
}

tricky part is that I could not find any reference on how to refer test classes path using gradle's DSL variables (ie., android.sourceSets.test.output). Using this relative path looks resonable.

In the refering projects one have to add line:

testCompile project(path: ':volley', configuration: 'tests')

Post a Comment for "Compile Jar With Test Classes"