Sample gradle file
Following details are part of previous blog
http://www.scmtechblog.net/2015/12/how-to-migrate-parent-pom-from-maven-to.html
Here is the sample of base gradle file which can be acted as super pom for your project.
There are 2 profiles we have enabled whitebox-analysis and Coverage-analysis which does complete checks and only jacoco respectively.
// File: base.gradle
allprojects {
afterEvaluate { project ->
if (project.hasProperty("whitebox-analysis")) {
project.apply plugin: 'java'
project.apply plugin: 'findbugs'
project.apply plugin: 'pmd'
project.apply plugin: 'checkstyle'
project.apply plugin: "jacoco"
// project.apply plugin: "sonar-runner"
findbugs {
ignoreFailures = true
effort = "max"
reportLevel = "high"
}
pmd {
ignoreFailures = true
ruleSets = ["basic"]
}
checkstyle {
ignoreFailures = true
configFile = file("/home/jenkins/scripts/checks.xml")
}
jacoco {
toolVersion = "0.7.1.201405082137"
}
jacocoTestReport {
description = "Generate Jacoco coverage reports after running tests."
sourceDirectories = files('src/java')
classDirectories = files('build/classes/main')
reports {
xml.enabled true
csv.enabled false
html.enabled true
}
}
check.dependsOn checkstyleMain, pmdMain, findbugsMain, jacocoTestReport
jacocoTestReport.dependsOn test
}
if (project.hasProperty("coverage-analysis")) {
project.apply plugin: 'java'
project.apply plugin: "jacoco"
project.apply plugin: 'maven'
jacoco {
toolVersion = "0.7.1.201405082137"
}
jacocoTestReport {
description = "Generate Jacoco coverage reports after running tests."
sourceDirectories = files('src/java')
classDirectories = files('build/classes/main')
reports {
xml.enabled true
csv.enabled false
html.enabled true
}
}
check.dependsOn jacocoTestReport
jacocoTestReport.dependsOn test
}
repositories {
maven {
name "central"
url "<give your URL>"
}
maven {
name "central2"
url "<give your URL>"
}
maven {
name "release-local"
url "<give your URL>"
}
maven {
name "snapshot-local"
url "<give your URL>"
}
maven {
name "plugin-release"
url "<give your URL>"
}
maven {
name "plugin-snapshot"
url "<give your URL>"
}
mavenLocal()
}
}
}
Here is One more gradle file as super pom which takes care of uploading the artifacts to the repository. You can call both init script with -I options.initscript { repositories { mavenCentral() maven { url "<Your mavne URL>"} } } allprojects { afterEvaluate { project -> project.apply plugin: 'maven' uploadArchives { repositories { mavenDeployer { pom.packaging = project.packaging pom.groupId = project.group pom.version = project.version pom.artifactId = project.artifactid if(project.version.endsWith('-SNAPSHOT')) { repository(url: '<Your snapshot Maven URL>') { authentication(userName: RepoUsernameProp, password: repoPasswordProp); } } else { repository(url: '<Your Release Maven URL>') { authentication(userName: RepoUsernameProp, password: repoPasswordProp); } } } } } } }You can call these scripts like following../gradle clean disk-Pwhitebox-analysis check-I /home/releasebot/jenkins/scripts/gradle/base.gradle-I /home/releasebot/jenkins/scripts/gradle/publish.gradle
Comments
Post a Comment