Showing posts with label gradle. Show all posts
Showing posts with label gradle. Show all posts

Saturday, March 5, 2016

Gradle : Complete build file

Gradle : Complete build file


https://github.com/codeborne/selenide/blob/master/build.gradle



buildscript {
  repositories { jcenter() }
  dependencies {
    classpath 'info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.1.9'
    classpath 'de.undercouch:gradle-download-task:2.1.0'
  }
}

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: "jacoco"
apply plugin: 'findbugs'
apply plugin: 'checkstyle'
apply plugin: 'de.undercouch.download'

group='com.codeborne'
archivesBaseName = 'selenide'
version='3.4'

[compileJava, compileTestJava]*.options.collect {options -> options.encoding = 'UTF-8'}
[compileJava, compileTestJava]*.options.collect {options -> options.debug = true}
compileJava.options.debugOptions.debugLevel = "source,lines,vars"
sourceCompatibility = 1.7
targetCompatibility = 1.7

defaultTasks 'check', 'test', 'install'

repositories {
  mavenCentral()
}

configurations {
  provided
  compile.extendsFrom provided
}

dependencies {
  compile('org.seleniumhq.selenium:selenium-java:2.52.0') {
    exclude group: 'org.seleniumhq.selenium', module: 'selenium-htmlunit-driver'
    exclude group: 'org.seleniumhq.selenium', module: 'selenium-android-driver'
    exclude group: 'org.seleniumhq.selenium', module: 'selenium-iphone-driver'
    exclude group: 'org.seleniumhq.selenium', module: 'selenium-safari-driver'
    exclude group: 'org.webbitserver', module: 'webbit'
    exclude group: 'commons-codec', module: 'commons-codec'
    exclude group: 'cglib', module: 'cglib-nodep'
  }
  runtime('com.codeborne:phantomjsdriver:1.2.1') {
    exclude group: 'org.seleniumhq.selenium', module: 'selenium-java' 
    exclude group: 'org.seleniumhq.selenium', module: 'selenium-remote-driver' 
  }
  compile 'com.google.guava:guava:19.0'
  runtime 'commons-codec:commons-codec:1.10'
  provided group: 'org.seleniumhq.selenium', name: 'selenium-htmlunit-driver', version: '2.52.0', transitive: false
  provided group: 'net.sourceforge.htmlunit', name: 'htmlunit', version: '2.20', transitive: false
  testRuntime group: 'net.sourceforge.htmlunit', name: 'htmlunit', version: '2.20'
  provided 'junit:junit:4.12'
  provided 'org.testng:testng:6.9.10'
 
  // For BrowserMob Proxy:
  testCompile group: 'net.lightbody.bmp', name: 'browsermob-proxy', version: '2.0.0', transitive: false
  testRuntime group: 'org.slf4j', name: 'slf4j-jdk14', version: '1.7.18'
  testRuntime group: 'net.sf.uadetector', name: 'uadetector-resources', version: '2014.10'
  testRuntime 'com.fasterxml.jackson.core:jackson-databind:2.7.2'

  testCompile 'org.mockito:mockito-core:1.10.19'
  testCompile 'org.eclipse.jetty:jetty-server:9.2.15.v20160210'
  testCompile 'org.eclipse.jetty:jetty-servlet:9.2.15.v20160210'
  testCompile 'commons-fileupload:commons-fileupload:1.3.1'
}

task libs(type: Sync) {
  from configurations.compile
  from configurations.runtime
  from configurations.testCompile
  from configurations.testRuntime
  into "$buildDir/lib"
}

compileJava.dependsOn libs

findbugs {
  toolVersion = "3.0.1"
  sourceSets = [sourceSets.main]
  effort = "max"
  reportsDir = file("$project.buildDir/reports/findbugs")
  excludeFilter = file("$rootProject.projectDir/config/findbugs/excludeFilter.xml")
}

tasks.withType(FindBugs) {
  reports {
    xml.enabled = false
    html.enabled = true
  }
}

task checkstyleHtmlMain << {
  ant.xslt(in: checkstyleMain.reports.xml.destination,
    style: file('config/checkstyle/checkstyle-noframes-sorted.xsl'),
    out: new File(checkstyleMain.reports.xml.destination.parent, 'main.html'))
}

task checkstyleHtmlTest << {
  ant.xslt(in: checkstyleTest.reports.xml.destination,
    style: file('config/checkstyle/checkstyle-noframes-sorted.xsl'),
    out: new File(checkstyleTest.reports.xml.destination.parent, 'test.html'))
}

checkstyleMain.finalizedBy checkstyleHtmlMain
checkstyleTest.finalizedBy checkstyleHtmlTest

jacoco {
  toolVersion = "0.7.6.201602180812"
}

jacocoTestReport {
  reports {
    xml.enabled false
    csv.enabled false
    html.destination "${buildDir}/reports/jacocoHtml"
  }
}

apply plugin: 'info.solidsoft.pitest'

pitest {
  targetClasses = ["com.codeborne.selenide*"]
  timestampedReports = false
  threads = 4
  outputFormats = ['XML', 'HTML']
  enableDefaultIncrementalAnalysis = true
}

test {
  include 'com/codeborne/selenide/**/*'
}

import de.undercouch.gradle.tasks.download.Download

task downloadIEDriverZip(type: Download) {
  src 'http://selenium-release.storage.googleapis.com/2.52/IEDriverServer_Win32_2.52.0.zip'
  dest new File(buildDir, 'IEDriverServer.zip')
  quiet false
  overwrite true
  onlyIfNewer true
  compress false
  println "Download IE driver: " + src
}

task downloadAndUnzipIEDriver(dependsOn: downloadIEDriverZip, type: Copy) {
  println "Unzip IE driver: " + downloadIEDriverZip.dest
  from zipTree(downloadIEDriverZip.dest)
  into buildDir
}

task ie(type: Test, dependsOn: downloadAndUnzipIEDriver) {
  println 'Use IE driver: ' + buildDir + '/IEDriverServer.exe'
  systemProperties['selenide.browser'] = 'ie'
  systemProperties['webdriver.ie.driver'] = new File(buildDir, 'IEDriverServer.exe')
  systemProperties['selenide.timeout'] = '8000'
  include 'integration/**/*'
  exclude '**/AlertText.*'
  exclude '**/ConfirmTest.*'
  exclude 'com/codeborne/selenide/**/*'
}

import org.gradle.internal.os.OperatingSystem;

task downloadChromeDriverZip(type: Download) {
  if (OperatingSystem.current().isMacOsX()) {
    src 'http://chromedriver.storage.googleapis.com/2.21/chromedriver_mac32.zip'
  }
  else if (OperatingSystem.current().isLinux()) {
    src 'http://chromedriver.storage.googleapis.com/2.21/chromedriver_linux64.zip'
  }
  else {
    src 'http://chromedriver.storage.googleapis.com/2.21/chromedriver_win32.zip'
  }
  dest new File(buildDir, 'chromedriver.zip')
  quiet false
  overwrite true
  onlyIfNewer true
  compress false
  println "Download Chrome driver: " + src + " to " + dest
}

task downloadAndUnzipChromeDriver(dependsOn: downloadChromeDriverZip, type: Copy) {
  println "Unzip Chrome driver: " + downloadChromeDriverZip.dest
  from zipTree(downloadChromeDriverZip.dest)
  into buildDir
}

task chrome(type: Test, dependsOn: downloadAndUnzipChromeDriver) {
  println 'Use Chrome driver: ' + buildDir + '/chromedriver'
  systemProperties['selenide.browser'] = 'chrome'
  systemProperties['webdriver.chrome.driver'] = new File(buildDir, 'chromedriver')
  include 'integration/**/*'
  exclude 'com/codeborne/selenide/**/*'
}

task htmlunit(type: Test) {
  systemProperties['selenide.browser'] = 'htmlunit'
  include 'integration/**/*'
  exclude 'com/codeborne/selenide/**/*'
}

task phantomjs(type: Test) {
  systemProperties['selenide.browser'] = 'phantomjs'
  include 'integration/**/*'
  exclude 'com/codeborne/selenide/**/*'
}

task firefox(type: Test) {
  systemProperties['selenide.browser'] = 'firefox'
  include 'integration/**/*'
  exclude 'com/codeborne/selenide/**/*'
}

tasks.withType(Test).all { testTask ->
  testTask.systemProperties['file.encoding'] = 'UTF-8'
  testTask.testLogging.showStandardStreams = true
  testTask.systemProperties['BUILD_URL'] = System.getenv()['BUILD_URL']
  testTask.maxParallelForks = 2
  testTask.jacoco {
    enabled = true
    includes = ['com/codeborne/selenide/**/*']
  }
  testTask.outputs.upToDateWhen { false }
}

task allTests(dependsOn: ['clean', 'test', 'chrome', 'firefox', 'htmlunit', 'phantomjs']) {}

jar {
  manifest {
    attributes(
      "Implementation-Title": project.group + '.' + project.name,
      "Implementation-Version": version,
      "Implementation-Vendor": "Codeborne")
  }
}

task sourcesJar(type: Jar, dependsOn:classes) {
  classifier = 'sources'
  from sourceSets.main.allSource
}

javadoc {
  failOnError=false
}

task javadocJar(type: Jar, dependsOn:javadoc) {
  classifier = 'javadoc'
  from javadoc.destinationDir
}

artifacts {
  archives jar
  archives sourcesJar
  archives javadocJar
}

task wrapper(type: Wrapper) {
  gradleVersion = '2.11'
  jarFile = './gradle-wrapper/gradle-wrapper.jar'
  scriptFile = './gradle'
}

Friday, March 4, 2016

Java : System.out.print not displaying

System.out.print not displaying





http://stackoverflow.com/questions/3963708/gradle-how-to-display-test-results-in-the-console-in-real-time


Example :


test {
    testLogging {
 events "passed", "skipped", "failed", "standardOut", "standardError"
 showStandardStreams = true
 
 }
}

Saturday, February 27, 2016

Gradle :File Operations

Gradle :File Opertions 



https://www.safaribooksonline.com/library/view/gradle-beyond-the/9781449373801/ch01.html

Gradle: A trivial copy task configuration

task copyPoems(type: Copy) {
  from 'text-files'
  into 'build/poems'
}


Gradle: A copy task that copies all the poems except the one by Henley

task copyPoems(type: Copy) {
  from 'text-files'
  into 'build/poems'
  exclude '**/*henley*'
}


Gradle: A copy task that only copies Shakespeare and Shelley

task copyPoems(type: Copy) {
  from 'text-files'
  into 'build/poems'
  include '**/sh*.txt'
}


Gradle: A copy task taking files from more than one source directory

task complexCopy(type: Copy) {
  from('src/main/templates') {
    include '**/*.gtpl'
  }
  from('i18n')
  from('config') {
    exclude 'Development*.groovy'
  }
  into 'build/resources'
}


Gradle: A copy task mapping source directory structure onto a new destination structure

task complexCopy(type: Copy) {
  from('src/main/templates') {
    include '**/*.gtpl'
    into 'templates'
  }
  from('i18n')
  from('config') {
    exclude 'Development*.groovy'
    into 'config'
  }
  into 'build/resources'
}


Gradle: Renaming files using regular expressions

task rename(type: Copy) {
  from 'source'
  into 'dest'
  rename(/file-template-(\d+)/, 'production-file-$1.txt')
}


Gradle: Renaming files programmatically

task rename(type: Copy) {
  from 'source'
  into 'dest'
  rename { fileName ->
    "production-file${(fileName - 'file-template')}"
  }
}

 
Gradle: Copying a file with keyword expansion

versionId = '1.6'

task copyProductionConfig(type: Copy) {
  from 'source'
  include 'config.properties'
  into 'build/war/WEB-INF/config'
  expand([
    databaseHostname: 'db.company.com',
    version: versionId,
    buildNumber: (int)(Math.random() * 1000),
    date: new Date()
  ])
}

Java :Classpath and library error even when dependencies are added to Gradle

Classpath and library error even when dependencies are added to Gradle


I have added all dependencies in "build.gradle" required for a selenium project.But still i am getting error when i try to launch a firefox driver using : WebDriver driver = new FirefoxDriver();


Solution : 
 
1. Make sure that you have imported the FirefoxDriver class in your code. Add the following line in your import section.

    import org.openqa.selenium.firefox.FirefoxDriver;

2. Clean the Gradle project (https://www.jetbrains.com/idea/help/gradle-tool-window.html)
3. Refresh the project (File>Synchronize)
4. Use the refresh button in Gradle Tool Window if ".gradle" file is edited
https://www.jetbrains.com/idea/help/gradle-tool-window.html


Note :All Dependencies add should appear in Gradle Tool Window >Dependencies

Tuesday, February 23, 2016

Java:Gradle Tut

Gradle



http://www.vogella.com/tutorials/Gradle/article.html
https://docs.gradle.org/current/userguide/tutorial_using_tasks.html
https://develosapiens.wordpress.com/2015/05/08/playing-with-gradle/
http://blog.bbv.ch/2012/09/12/the-gradle-build-system-a-short-overview/
http://www.drdobbs.com/jvm/writing-build-scripts-with-gradle/240168648?pgno=1