Skip to content

Instantly share code, notes, and snippets.

@mychaelstyle
Created March 28, 2014 06:04
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save mychaelstyle/9826322 to your computer and use it in GitHub Desktop.
Save mychaelstyle/9826322 to your computer and use it in GitHub Desktop.
Example Gradle build Java with FindBugs and PMD and CPD
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'
}
@typekpb
Copy link

typekpb commented Nov 21, 2017

how about mavenLocal() instead of: maven { url 'file:'+System.getenv('HOME')+'/.m2/repository' } ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment