【发布时间】:2016-05-30 22:40:16
【问题描述】:
如何在 android 中编译带有测试类的 jar?我正在使用 android gradle 插件 1.3.1:
classpath 'com.android.tools.build:gradle:1.3.1'
我试过了:
task testSourcesJar(type: Jar) {
from android.sourceSets.test.java.srcDirs
}
它创建的正是定义的内容:一个带有测试源的 jar,而不是编译的类。编译的类在哪里以及我应该依赖哪个任务来创建带有测试类的 jar?
我需要它来为另一个项目准备测试工件,该项目必须扩展一些测试类。
下面是我修改的整个 build.gradle。这是 google 的 volley 库。
// NOTE: The only changes that belong in this file are the definitions
// of tool versions (gradle plugin, compile SDK, build tools), so that
// Volley can be built via gradle as a standalone project.
//
// Any other changes to the build config belong in rules.gradle, which
// is used by projects that depend on Volley but define their own
// tools versions across all dependencies to ensure a consistent build.
//
// Most users should just add this line to settings.gradle:
// include(":volley")
//
// If you have a more complicated Gradle setup you can choose to use
// this instead:
// include(":volley")
// project(':volley').buildFileName = 'rules.gradle'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}
apply plugin: 'com.android.library'
repositories {
jcenter()
}
android {
compileSdkVersion 22
buildToolsVersion = '22.0.1'
}
task testSourcesJar(type: Jar, dependsOn: 'testClasses') {
from android.sourceSets.test.java.srcDirs
}
configurations {
testArtifacts
}
artifacts {
testArtifacts testSourcesJar
}
apply from: 'rules.gradle'
【问题讨论】:
-
类似的问题在这里解决了:stackoverflow.com/a/5153162/1201833,但显然它与android无关(没有testClasses任务)。
标签: android android-gradle-plugin