-
-
Save haivenki/0d21bd2ad093d340465984293ac28554 to your computer and use it in GitHub Desktop.
Example Gradle build Java with FindBugs and PMD and CPD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: "java" | |
apply plugin: "eclipse" | |
apply plugin: "maven" | |
apply plugin: "findbugs" | |
apply plugin: "pmd" | |
def defaultEncoding = 'UTF-8' | |
[compileJava, compileTestJava]*.options*.encoding = defaultEncoding | |
sourceCompatibility = 1.7 | |
targetCompatibility = 1.7 | |
group = 'com.mychaelstyle' | |
archivesBaseName = 'MyLibs' | |
version = '0.1.0' | |
repositories { | |
mavenCentral() | |
maven { | |
url 'file:'+System.getenv('HOME')+'/.m2/repository' | |
} | |
} | |
dependencies { | |
testCompile "junit:junit:4.11" | |
compile 'log4j:log4j:1.2.17' | |
runtime fileTree(dir: 'libs', include: '*.jar') | |
} | |
uploadArchives { | |
repositories { | |
mavenDeployer { | |
file(System.getenv('HOME')+'/.m2/repository').mkdirs() | |
repository(url: 'file:'+System.getenv('HOME')+'/.m2/repository') | |
} | |
} | |
} | |
jar { | |
manifest { | |
attributes 'Implementation-Title': 'MyLibs', 'Implementation-Version': 0.1 | |
attributes "Main-Class" : "com.mychaelstyle.Main" | |
} | |
from configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } | |
} | |
task writePom << { | |
pom { | |
project { | |
inceptionYear '2014' | |
licenses { | |
license { | |
name 'The Apache Software License, Version 2.0' | |
url 'http://www.apache.org/licenses/LICENSE-2.0.txt' | |
distribution 'repo' | |
} | |
} | |
} | |
}.writeTo("$projectDir/pom.xml") | |
} | |
findbugs { | |
ignoreFailures = true | |
toolVersion = "2.0.1" | |
sourceSets = [sourceSets.main] | |
reportsDir = file("$project.buildDir/reports/findbugs") | |
effort = "max" | |
} | |
pmd { | |
ignoreFailures = true | |
sourceSets = [sourceSets.main] | |
reportsDir = file("$project.buildDir/reports/pmd") | |
ruleSets = [ | |
"basic", | |
"braces" | |
] | |
} | |
// add CPD to check | |
check << { | |
File outDir = new File('build/reports/pmd/') | |
outDir.mkdirs() | |
ant.taskdef(name: 'cpd', classname: 'net.sourceforge.pmd.cpd.CPDTask', | |
classpath: configurations.pmd.asPath) | |
ant.cpd(minimumTokenCount: '100', format: 'xml', | |
outputFile: new File(outDir , 'cpd.xml')) { | |
fileset(dir: "src/main/java") { | |
include(name: '**/*.java') | |
} | |
} | |
} | |
// gradle wrapper | |
task wrapper(type: Wrapper) { | |
gradleVersion = '1.9' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment