这确实是一个愚蠢的菜鸟错误。我们正在使用一个多项目设置,其中包含一个主项目和几个位于同一级别的文件夹,其中包含代码和测试。在
build.gradle我使用不慎唯一配置的主项目使用TestNG的。解决方案是将测试目标包含在
allprojects或
subprojects闭合内。这里解释:所有项目和子项目之间有什么区别
所以这里是工作
build.gradle:
def mainClassName = 'nl.xillio.contentplatform.view.Run'// Load settings for all projects including master and subprojectsallprojects { apply plugin: 'java' apply plugin: 'eclipse' version '0.1' repositories { mavenCentral() maven { url 'http://mvnrepository.com/maven2' } maven { url 'http://download.java.net/maven/2' } }}// Load the dependencies for all subprojects (layers)subprojects { dependencies { //to do: move these to the correct subprojects compile 'javax.inject:javax.inject:1' compile 'org.springframework:spring-context:4.1.4.RELEASE' compile 'org.springframework:spring-core:4.1.4.RELEASE' compile 'org.springframework:spring-beans:4.1.4.RELEASE' compile 'commons-logging:commons-logging:1.2' testCompile 'org.springframework:spring-test:4.1.4.RELEASE' testCompile 'org.testng:testng:6.1.1' } test { // enable TestNG support (default is JUnit) useTestNG() }}// Resolve the dependencies between the layers in the individual project's build.gradle files// add onLY specific per project behaviour of the GLOBAL build here:project(':contentplatform-web') {}project(':contentplatform-service') {}project(':contentplatform-dao') {}// Return a list of all the external librariesdef getLibraries() { return configurations.runtime.filter{!it.name.startsWith('contentplatform')}}// Copy all the libraries to a libs foldertask copyLibraries(type: Copy) { group 'Content Platform' description 'Copy all the external libraries to the /libs folder.' destinationDir file('./build/') into('libs/') { from getLibraries() }}// Perform the build task before building the big jarjar { group 'Content Platform' description 'Package all the layers and dependencies into a big jar.' // The libraries are required to build dependsOn(copyLibraries) // The final big jar needs all the layers dependencies { compile project(':contentplatform-web'), project(':contentplatform-dao'), project(':contentplatform-service'), project(':contentplatform-model') } // Create a MANIFEST.MF file, the main class file is in the web layer manifest { attributes 'Implementation-Title': 'Content Platform', 'Implementation-Version': version, 'Built-By': System.getProperty('user.name'), 'Built-Date': new Date(), 'Built-JDK': System.getProperty('java.version'), 'Class-Path': getLibraries().collect{'../libs/' + it.getName()}.join(' '), 'Main-Class': mainClassName } // Include the layers in the fat jar from(configurations.compile.filter{it.name.startsWith('contentplatform')}.collect{it.isDirectory() ? it : zipTree(it) }) { exclude "meta-INF/*.SF" exclude "meta-INF/*.DSA" exclude "meta-INF/*.RSA" } // Save the fat jar in the root of the folder instead of in build/libs destinationDir file('.')}


