我正在尝试包含已编译的类(来自project3)以运行junit测试。
这是一个简短的项目结构。
project1
build.gradle
project2
build.gradle
project3
src/main/java/***.java
src/test/java/***JunitTestClasses
build.gradle - I am running this.
这是来自project3的build.gradle。
apply plugin: 'java'
apply plugin: "jacoco"
apply plugin: 'maven'
apply plugin: 'com.github.jacobono.jaxb'
apply plugin: "io.spring.dependency-management"
sourceCompatibility = 1.8
targetCompatibility = 1.8
buildscript {
repositories {
maven
{
// omitted.
}
}
dependencies
{
classpath 'com.github.jacobono:gradle-jaxb-plugin:' + GRADLE_JAXB_PLUGIN_VERSION
classpath 'io.spring.gradle:dependency-management-plugin:' + GRADLE_DEP_MGMT_PLUGIN_VERSION
}
}
dependencies
{
compile project(':project1')
compile project(':project2')
compile project(':project3')
compile group: 'org.apache.ant', name: 'ant', version: ANT_VERSION
jaxb group: 'com.sun.xml.bind', name: 'jaxb-xjc', version: JAXB_VERSION
jaxb group: 'com.sun.xml.bind', name: 'jaxb-impl', version: JAXB_VERSION
jaxb group: 'com.sun.xml.bind', name: 'jaxb-core', version: JAXB_VERSION
xmlbeans 'org.apache.xmlbeans:xmlbeans:2.5.0'
testCompile group: 'junit', name: 'junit', version: '4.+'
runtime files('build/classes/main')
}
configurations {
repobootstrap
xmlbeans
}
sourceSets {
generated {
java {
srcDir file("${buildDir}/generated")
}
}
testGenerated {
compileClasspath += sourceSets.main.runtimeClasspath
java {
srcDir file("${buildDir}/generated")
}
}
main {
compileClasspath += sourceSets.generated.output
runtimeClasspath += sourceSets.generated.output
}
test {
compileClasspath += sourceSets.generated.output
runtimeClasspath += sourceSets.generated.output
}
}
test
{
systemProperties 'basedir': projectDir
systemProperties 'testdir': "${projectDir}/src/test"
systemProperties 'resourcedir': "${projectDir}/src/test/resources"
systemProperties 'TARGET': "${buildDir}/tmp"
systemProperties 'tmp.dir': "${buildDir}/tmp"
}
从XSD生成类的一些任务被省略。
当我做gradle build'时,它成功地从XML生成类并编译。但是当junit测试运行时,它会抛出java.lang.NoClassDefFoundError'对于属于project3和' java.lang.ClassNotFoundException的类:schemaorg_apache_xmlbeans.system.sE2A73A83DA959459556520519D4CA82A.TypeSystemHolder'。 xmlbeans的生成工件位于生成的\ schemaorg_apache_xmlbeans3下,编译的类位于project3 / build / main
下如果有人有任何线索,我会很感激。