apply plugin: 'eclipse' apply plugin: 'findbugs' apply plugin: 'jacoco' apply plugin: 'java' apply plugin: 'jdepend' apply plugin: 'maven' apply plugin: 'tomcat' apply plugin: 'war' group = 'de.krismer' status = 'snapshot' version = '1.0' if (status.equalsIgnoreCase("snapshot")) { version += '-SNAPSHOT' } configurations { sql } repositories { mavenCentral() } buildscript { apply from: 'http://www.krismer.de/files/checkstyle.gradle' repositories { mavenCentral() } dependencies { classpath 'org.gradle.api.plugins:gradle-tomcat-plugin:0.9.8' } } [checkstyle, findbugs, jdepend, test]*.ignoreFailures = true [tomcatRun, tomcatRunWar]*.outputFile = file('build/catalina.out') [tomcatRun, tomcatRunWar, tomcatStop]*.stopPort = 8090 [tomcatRun, tomcatRunWar, tomcatStop]*.stopKey = 'stopKey' dependencies { def tomcatVersion = '7.0.39' // compile time dependencies compile 'mysql:mysql-connector-java:5.1.24' compile 'jstl:jstl:1.2' compile 'asm:asm:3.1' compile 'com.sun.jersey:jersey-bundle:1.17.1' compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.12' // dependencies for maven repository deployment archives 'org.apache.maven.wagon:wagon-http:2.2' // provided compile dependencies providedCompile "org.apache.tomcat:tomcat-catalina:${tomcatVersion}" providedCompile 'javax.servlet:javax.servlet-api:3.0.1' // database dependencies sql 'mysql:mysql-connector-java:5.1.16' // test dependencies testCompile 'org.testng:testng:6+' testCompile 'org.seleniumhq.selenium:selenium-java:2.32.0' // tomcat dependencies tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}" tomcat "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}" tomcat("org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}") { exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj' } } checkstyle { showViolations = false } jar { description = 'Builds a jar file (without libraries)' appendix = 'dynamic' } test { dependsOn("war") dependsOn("setupDatabase") description = 'Starts a tomcat instance and runs the tests against it' useTestNG() doFirst { tomcatRunWar.daemon = true tomcatRunWar.execute() } doLast { tomcatStop.execute() } } uploadArchives { repositories.mavenDeployer { repository(url: repositoryPrefix + 'releases') { authentication(userName: repositoryUsername, password: repositoryPassword) } snapshotRepository(url: repositoryPrefix + 'snapshots') { authentication(userName: repositoryUsername, password: repositoryPassword) } } } war { description = 'Builds a war file including sources' // included sources and .properties files from('src/main/java') { include '**/*' into('WEB-INF/classes') } } task javadocJar(type: Jar, dependsOn: javadoc) { description = 'Builds a jar file including javadoc' appendix = 'javadoc' from javadoc.destinationDir } task sourcesJar(type: Jar, dependsOn: classes) { description = 'Builds a jar file including sources' appendix = 'sources' from sourceSets.main.allSource } task staticJar(type: Jar) { description = 'Builds a jar file including all libraries' appendix = 'static' from sourceSets.main.output from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } } task staticTestJar(type: Jar) { description = 'Builds a jar file including all libraries and test classes' appendix = 'staticWithTests' from sourceSets.main.output from sourceSets.test.output from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } } task packageAll(dependsOn: [jar, war, javadocJar, sourcesJar, staticJar, staticTestJar]) task setupDatabase << { ant.sql( src: 'src/test/resources/setupDb.sql', classpath: configurations.sql.asPath, driver:'com.mysql.jdbc.Driver', onerror: 'continue', password: 'jenkins', print: true, url: 'jdbc:mysql://localhost:3306/?useUnicode=true&characterEncoding=UTF-8', userid: 'jenkins' ) }