I am working on one script wherer I have two task
Add runtime dependency in POM file during gradle build and then create the artifact and upload it to the artifactory.Now my artifact is having POM file and the zip file.Zip file consist of lib folder and jar file.lib folder is having lots of other jar files which I put during my build.But there are two dependency which I don’t want to include in lib folder but wants to add it in the POM file which I am able to do it sucessfully.
Now my task is while I will deploy this artifact which is basically a zip file then my logic will read the POM file and it will fetch the runtime dependency during deployment.from the artifactory and will unzip it.I am not sure how to get the runtime dependency during deployment.
apply plugin: 'java’
apply plugin: 'jacoco’
apply plugin: 'findbugs’
apply plugin: 'pmd’
apply plugin: 'checkstyle’
apply plugin: ‘maven’
//-- set the group for publishing
group = ‘c.tr.ana’
/**
- Initializing GAVC settings
*/
def buildProperties = new Properties()
file(“version.properties”).withInputStream {
stream -> buildProperties.load(stream)
}
//add the jenkins build version to the version
def env = System.getenv()
if (env[“BUILD_NUMBER”]) buildProperties.analyticsengineBuildVersion += ".${env[“BUILD_NUMBER”]}"
version = buildProperties.analyticsengineBuildVersion
println “${version}”
//name is set in the settings.gradle file
group = "c.tr.ana"
version = buildProperties.analyticsengineBuildVersion
println “Building ${project.group}:${project.name}:${project.version}”
sourceCompatibility = 1.7
compileJava.options.encoding = ‘UTF-8’
repositories {
maven { url "http://cm.t.t.co:8/aactory/filease-local" }
}
dependencies {
compile group: ‘c.tr.ana’, name: ‘common’, version:'4.0.0.100’
compile group: ‘c.tr.ana’, name: ‘LicenseVerifier’, version:'4.0.0.90’
compile group: ‘c.tr.ana’, name: ‘AnalyticsLib’, version: '4.0.0.137’
compile group: ‘c.tr.ana’, name: ‘Integration’, version: '4.0.0.97’
compile group: ‘c.operasolutions’, name: ‘RiskAnalytics’, version:'1.1’
compile group: ‘commons-configuration’, name: ‘commons-configuration’, version:'1.10’
compile group: ‘com.jamonapi’, name: ‘jamon’, version:'2.4’
compile group: ‘ch.qos.logback’, name: ‘logback-classic’, version:'1.1.1’
compile group: ‘ch.qos.logback’, name: ‘logback-core’, version:'1.1.1’
compile group: ‘org.slf4j’, name: ‘slf4j-api’, version:'1.7.6’
compile group: ‘net.sf.supercsv’, name: ‘super-csv-dozer’, version:'2.1.0’
compile group: ‘net.sf.supercsv’, name: ‘super-csv’, version:'2.1.0’
compile group: ‘org.codehaus.mojo’, name: ‘properties-maven-plugin’, version:'1.0-alpha-2’
compile group: ‘args4j’, name: ‘args4j’, version:'2.0.28’
compile group: ‘org.codehaus.jackson’, name: ‘jackson-mapper-asl’, version:'1.9.5’
testCompile group: ‘junit’, name: ‘junit’, version:'4.11’
testCompile group: ‘org.mockito’, name: ‘mockito-all’, version:‘1.9.5’
}
dependencies {
runtime group: ‘c.tr.ana’, name: ‘ae-libs’, version: ‘0.0.5’, classifier: ‘linux’, ext: 'zip’
runtime group: ‘c.tr.ana’, name: ‘reference-files’, version: ‘0.0.3’, classifier: ‘linux’, ext: ‘zip’
}
jacoco {
toolVersion = “0.7.1.201405082137”
}
test {
jacoco {
append = false
destinationFile = file("$buildDir/jacoco/jacocoTest.exec")
classDumpFile = file("$buildDir/jacoco/classpathdumps")
}
}
jacocoTestReport {
group = "Reporting"
description = "Generate Jacoco coverage reports after running tests."
executionData = fileTree(dir: ‘build/jacoco’, include: ‘**/*.exec’)
reports {
xml{
enabled true
//Following value is a file
destination "${buildDir}/reports/jacoco/xml/jacoco.xml"
}
csv.enabled false
html{
enabled true
//Following value is a folder
destination "${buildDir}/reports/jacoco/html"
}
}
}
findbugs {
ignoreFailures = true
//sourceSets = [sourceSets.main]
}
pmd {
ruleSets = [“java-basic”, “java-braces”, “java-design”]
ignoreFailures = true
//sourceSets = [sourceSets.main]
}
checkstyle {
configFile = new File(rootDir, “config/checkstyle.xml”)
ignoreFailures = true
//sourceSets = [sourceSets.main]
}
// adding test report to taskGraph
build.dependsOn jacocoTestReport
def pomFile = file("${buildDir}/libs/${archivesBaseName.toLowerCase()}-${version}.pom")
task newPom << {
pom {
project {
groupId project.group
artifactId project.name
version project.version
description = “Configuration Management Gradle Plugin”
}
}.writeTo(pomFile)
}
// adding pom generation to taskGraph
build.dependsOn newPom
//disabling the install task since we’re not using maven for real
install.enabled = false
//for publishing to artifactory via jenkins
if(project.hasProperty(‘artifactoryPublish’)) {
artifactoryPublish {
mavenDescriptor pomFile
}
}
jar {
// Keep jar clean:
exclude ‘META-INF/.SF’, 'META-INF/.DSA’, ‘META-INF/.RSA’, 'META-INF/.MF’
manifest {
attributes ‘Manifest-Version’: ‘1.0’,
‘Implementation-Title’: ‘CLI’,
‘Implementation-Vendor-Id’: ‘c.tr.ana’,
‘Build-Jdk’: ‘1.7.0_45’,
‘Main-Class’: ‘c.tr.ana.cli.App’,
‘Class-Path’: configurations.compile.files.collect { “lib/$it.name” }.join(’ ')
}
}
task buildreportZip( type: Zip, overwrite:true ) {
//Delete zip if already exist.
delete “build/libs/CLI-${project.version}-CLI.zip”
archiveName "CLI-${project.version}-CLI.zip"
def dirName = "build/libs"
def dirDest = new File ( dirName )
dirDest.mkdirs()
destinationDir dirDest
into ("") {
from "build/libs"
include "*${project.name}-${project.version}.jar"
}
into ( "lib" ) {
from configurations.compile
// exclude '*.zip'
}
}
// adding test report to taskGraph
//build.dependsOn buildreportZip
project.buildreportZip.dependsOn jar
//task artifact(type: DefaultTask, dependsOn: [‘buildreportZip’]) {}
// ------ Publish the jar file to artifactory ------
artifacts {
archives buildreportZip
}