我在Android Studio 2.2.3中有一个多项目Gradle构建,包含Java库(core
和codegen
)和Android库(android
)模块。 Make Project
显示Gradle控制台中执行的任务:
Executing tasks: [:android:generateDebugSources, :android:generateDebugAndroidTestSources, :android:mockableAndroidJar, :android:prepareDebugUnitTestDependencies, :android:compileDebugSources, :android:compileDebugAndroidTestSources, :android:compileDebugUnitTestSources, :codegen:compileJava, :core:compileJava]
但是compileJava
仅编译主类路径,而不是测试,并且未列出testClasses
和core
的{{1}}任务。另一方面,codegen
确实运行./gradlew build
。
如何为Java库模块进行Android Studio编译测试?
testClasses
:
settings.gradle
主要include 'core'
include 'codegen'
include 'android'
:
build.gradle
buildscript {
repositories {
maven {
url "http://10.122.85.159:9081/nexus/content/groups/public"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven {
url "http://10.122.85.159:9081/nexus/content/groups/public"
}
}
}
dependencies {
}
:
core/build.gradle
apply plugin: 'java'
version = '1.0.0'
sourceCompatibility = '1.7'
sourceSets {
generated {
java {
srcDirs = ['src/generated/java']
}
}
}
test {
filter {
}
}
dependencies {
compile fileTree(dir: '../lib', include: '*.jar')
generatedCompile project(':core')
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0'
compile 'org.javatuples:javatuples:1.2'
}
:
codegen/build.gradle
apply plugin: 'java'
dependencies {
compile project(':core')
compile group: 'com.squareup', name: 'javapoet', version: '1.8.0'
}
:
android/build.gradle