We just started using Gradle and TestNG on our project, so I am checking whether failing any test actually fails the build. I was quite surprised to see it does not. The tes
It was a stupid noob mistake indeed. We are using a multi-project setup with a master project and several folders on the same level, which contain the code and the tests. The build.gradle
I was using accidentally only configured the master project to use TestNG. The solution is to include the test target within the allprojects
or subprojects
closure. Which is explained here: What is the difference between allprojects and subprojects
So here is the working build.gradle
:
def mainClassName = 'nl.xillio.contentplatform.view.Run'
// Load settings for all projects including master and subprojects
allprojects {
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 libraries
def getLibraries() {
return configurations.runtime.filter{!it.name.startsWith('contentplatform')}
}
// Copy all the libraries to a libs folder
task 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 jar
jar {
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('.')
}