How to enable Allure history using Gradle and Junit5? - gradle

I know I could copy the history directory from allure-reports to a generated allure-results, and then do allure generate to get the history to show up, but I am looking for a way to achieve this with the built-in functionality in allure-gradle.
Currently, I run ./gradlew clean test, then ./gradlew allureReport, and this gives me a fresh html report with no history or reruns. I have noticed that the test task deletes the entire allure-reports directory and then re-makes and re-populates it.
Here is my build.gradle:
buildscript {
repositories {
mavenLocal()
jcenter()
}
}
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
id 'java'
id 'eclipse'
// Allure reporter
id 'io.qameta.allure' version '2.8.1'
}
repositories {
mavenCentral()
jcenter()
}
def allureVersion = "2.13.1"
allure {
autoconfigure = true
version = allureVersion
useJUnit5 {
version = '2.0-BETA10'
}
downloadLink = "https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline/2.13.1/allure-commandline-2.13.1.zip"
}
test {
useJUnitPlatform() {
includeEngines 'junit-jupiter'
}
ignoreFailures = true
}
dependencies {
compile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.6.0'
compile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.6.0'
compile group: 'org.junit.platform', name: 'junit-platform-launcher', version: '1.6.0'
// Needed as a workaround for JUnit 5 not failing tests that stopped due to an error message. The fix is in eclipse 4.10
compile group: 'org.junit.vintage', name: 'junit-vintage-engine', version: '5.6.0'
compile group: 'io.qameta.allure', name: 'allure-junit5', version: '2.13.1'
compile group: 'io.qameta.allure', name: 'allure-java-commons', version: '2.13.1'
// https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59'
}
I have also tried specifying the results and reports directories to be outside of the build directory, like this:
allure {
autoconfigure = true
version = allureVersion
resultsDir = file('../../allure-results')
reportDir = file('../../allure-report')
...
}
This allows the allure-results folder to keep the previous report, which show up as retries (not quite right), but history still doesn't work.

I have solved this problem by adding at the running test script these lines( I have some tests scuites)
call gradlew test -PsuiteFile=YOUR_TEST_SUITE.xml
mkdir allure-results\history
xcopy build\allure-results\* allure-results\history
allure serve allure-results\history
So I have added folder allure-results\history to keep all results

Related

hipi gradle build error

root#ubuntu:/usr/local/hipi# gradle
FAILURE: Build failed with an exception.
Where:
Build file '/usr/local/hipi/core/build.gradle' line: 8
What went wrong:
A problem occurred evaluating project ':core'.
Could not find method distributions() for arguments [build_7msgs7jcv6q1ci90h6pi2434k3$_run_closure2#39d1aa64] on project ':core'.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 7.635 secs
Build.gradle code :
defaultTasks 'install'
allprojects {
apply plugin: 'eclipse'
}
subprojects {
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile 'org.apache.hadoop:hadoop-common:2.7.1'
compile 'org.apache.hadoop:hadoop-mapreduce-client-core:2.7.1'
compile 'com.googlecode.json-simple:json-simple:1.1.1'
compile 'com.drewnoakes:metadata-extractor:2.8.1'
compile 'com.twelvemonkeys.imageio:imageio-jpeg:3.1.1'
compile 'com.twelvemonkeys.imageio:imageio-pnm:3.1.1'
compile 'com.twelvemonkeys.imageio:imageio-tiff:3.1.1'
compile group: 'org.bytedeco', name: 'javacpp', version: '1.0'
compile group: 'org.bytedeco', name: 'javacv', version: '1.0'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.0.0-1.0'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.0.0-1.0', classifier: 'macosx-x86_64'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.0.0-1.0', classifier: 'linux-x86_64'
compile group: 'org.bytedeco.javacpp-presets', name: 'opencv', version: '3.0.0-1.0', classifier: 'windows-x86_64'
testCompile "junit:junit:4+"
}
}
task install {
dependsOn(':tools:hibImport:jar')
dependsOn(':tools:hibDownload:jar')
dependsOn(':tools:hibInfo:jar')
dependsOn(':tools:hibToJpeg:jar')
dependsOn(':tools:hibDump:jar')
dependsOn(':tools:covar:jar')
doLast {
println '\nFinished building the HIPI library along with all tools and examples.'
}
}
The problem is in core folder's gradle file. Can you show me that file?
The content of core's directory gradle file should be :
apply plugin: 'java-library-distribution'
jar {
baseName = 'hipi'
version = '2.1.0'
}
distributions {
main{
baseName = 'hipi'
version = '2.1.0'
}
}
javadoc {
title = "HIPI - Hadoop Image Processing Interface"
options.links("http://docs.oracle.com/javase/8/docs/api/",
"http://hadoop.apache.org/docs/stable/api/",
"http://javadoc.metadata-extractor.googlecode.com/git/2.7.0/",
"http://bytedeco.org/javacpp-presets/opencv/apidocs/")
}
test {
testLogging.showStandardStreams = true
}

Gradle Plugin Execution Order

I have written this gradle file
group 'com.abhi'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'org.flywaydb.flyway'
sourceCompatibility = 1.8
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.flywaydb:flyway-gradle-plugin:3.2.1'
classpath 'org.jooq:jooq-codegen:3.7.1'
classpath 'com.h2database:h2:1.4.177'
}
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.jooq', name: 'jooq', version: '3.7.1'
compile group: 'org.jooq', name: 'jooq-meta', version: '3.7.1'
compile group: 'org.jooq', name: 'jooq-codegen', version: '3.7.1'
runtime group: 'com.h2database', name: 'h2', version: '1.4.177'
}
flyway {
url = 'jdbc:h2:file:target/foobar'
user = 'sa'
}
def writer = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(writer)
.configuration('xmlns': 'http://www.jooq.org/xsd/jooq-codegen-3.7.0.xsd') {
jdbc() {
driver('org.h2.Driver')
url('dbc:h2:file:target/foobar')
user('sa')
password('')
}
generator() {
database() {
}
generate() {
}
target() {
packageName('com.abhi.jooq.models')
directory('src/main/java')
}
}
}
// Run the code generator
// ----------------------
org.jooq.util.GenerationTool.generate(
javax.xml.bind.JAXB.unmarshal(new StringReader(writer.toString()), org.jooq.util.jaxb.Configuration.class)
)
when I say gradle compile it throws an exception
Could not load schemata
java.lang.NullPointerException
at org.jooq.impl.MetaImpl.meta(MetaImpl.java:120)
at org.jooq.impl.MetaImpl.getCatalogs(MetaImpl.java:143)
at org.jooq.impl.MetaImpl.getSchemas(MetaImpl.java:168)
at org.jooq.util.jdbc.JDBCDatabase.getSchemasFromMeta(JDBCDatabase.java:135)
at org.jooq.util.jdbc.JDBCDatabase.getSchemata0(JDBCDatabase.java:124)
at org.jooq.util.AbstractDatabase.getSchemata(AbstractDatabase.java:279)
I think the problem is that the code at the bottom of the script executes much before the "flyway" plugin.
Is there a way I can ensure that the code below is executed only after the flyway plugin has executed?
Yes, if you suppose, the problem is in execution order, then you can modify it, just like with any other tasks. Take a look at the documentation of the flyway plugin. According to it, this plugin adds some extra tasks to your build script, for thos one tasks are: flywayMigrate, flywayClean etc. You can make any of your tasks depending (with dependsOn option) on the tasks form this plugin and make them running just after the plugin's job is done.

Gradle does nothing on distZip task from distribution plugin

I have a Problem with the distribution Plugin of Gradle. I just want to use the plugin to bundle all my files together (jar's, shell-scripts, ...).
Here my build.gradle:
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: 'distribution'
sourceCompatibility = 1.7
targetCompatibility = 1.7
publishing {
...
}
repositories {
mavenCentral()
}
dependencies {
// public libraries
compile group: 'javax', name: 'javaee-api', version: '7.0'
compile group: 'javax.mail', name: 'javax.mail-api', version: '1.5.2'
compile group: 'commons-cli', name: 'commons-cli', version: '1.2'
compile group: 'org.apache.axis', name: 'axis', version: '1.4'
compile group: 'org.apache.axis', name: 'axis-jaxrpc', version: '1.4'
compile group: 'commons-discovery', name: 'commons-discovery', version: '0.4'
compile group: 'commons-logging', name: 'commons-logging', version: '1.1.1'
compile group: 'wsdl4j', name: 'wsdl4j', version: '1.6.2'
compile group: 'javax.xml.soap', name: 'saaj-api', version: '1.3'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.10'
runtime group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.2'
// this is a dirty workaround
// because I don't have deploy rights on artifactory and nobody has time for deploying my artifacts
compile fileTree(dir: 'lib', include: '*.jar')
}
Here the output:
$ ./gradlew distTar
Defaulting memory setting '-Xmx1024M'...
:distZip UP-TO-DATE
BUILD SUCCESSFUL
Total time: 2.44 secs
And nothing happens. No Zip File is created.
I'm using the latest version of Gradle (2.2.1)
Important for me is also, that I can use the installDist option of the plugin.
Any Ideas what's going wrong?
I found out what the Problem was:
The distZip wasn't working, because there were no files or libraries configured to be packed into the archive. By default, only the src/$distribution.name/dist is considered. The rest must be specified.
To ensure that at least the jar-File of the project is contained too, I used the plugin "java-library-distribution" instead of "distribution"
Furthermore I specified more files to consider:
distributions {
main {
contents {
from { 'distrib' }
}
}
}
If your $buildDir is empty, you have to configure a distribution:
distributions {
main {
baseName = 'someName'
contents {
from { 'src/readme' }
}
}
}
Also see https://gradle.org/docs/current/userguide/distribution_plugin.html

How to set system property using gradle?

I was wondering if it's possible to set a system property, for a Java application, using Gradle?
I tried using gradle.properties file and defining a property as
systemProp.name = my name
but then when I try to get that property from a Java application using
System.getProperty("name")
that property is not found.
build.gradle and gradle.properties are in root folder of the project.
This is what my build.gradle looks like:
apply plugin: 'war'
apply plugin: 'appengine'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.8.6'
}
}
appengine {
httpPort = 8081
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.google.inject', name: 'guice', version: '3.0'
compile group: 'com.google.inject.extensions', name: 'guice-servlet', version: '3.0'
compile group: 'javax.servlet', name: 'servlet-api', version: '2.5'
compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '4.2.0.Final'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.27'
compile 'com.google.protobuf:protobuf-java:2.5.0'
compile 'com.google.appengine:appengine-api-1.0-sdk:1.8.6'
compile 'com.google.template:soy:2012-12-21'
compile 'org.json:json:20090211'
}
And this is what my build.properties look like:
systemProp.firstName=Marko
systemProp.lastName=Vuksanovic
This is part of an AppEngine application and I run it using the following command:
gradle appengineRun
This is how I do it, setting props for Selenide test framework:
test {
systemProperty "browser", "chrome"
systemProperty "webdriver.chrome.driver", "$projectDir/drivers/chromedriver"
}
I just stumbled on this for use with the gradle application plugin. Add to the run task. Works great:
run {
systemProperties['MYPROP'] = '/my/prop/value'
}
This is what worked for me (using Kotlin DSL):
tasks.withType<JavaExec> {
systemProperty("key", "value")
}
The system property set in gradle.properties will be available only in JVM where Gradle is running.
From gradle-appengine-plugin documentation:
appengineRun: Starts a local development server running your project
code.
jvmFlags: The JVM flags to pass on to the local development server.
If you need your system properties to be available in app engine, which is separate JVM, you should use jvmFlags property.
Explicitly:
appengine {
jvmFlags = ['-DfirstName=Marko', '-DlastName=Vuksanovic']
}
With gradle.properties:
appengine {
jvmFlags = ['-DfirstName=$firstName', '-DlastName=$lastName']
}

tasks.setupAll.dependsOn(copyJars) does not work in gradle?

I tried following the answer here
how to override a task making it depend on one of mine in gradle
but it fails with
Could not find property 'setupAll' on task set.
I have tried a few things
Make the task in subprojects section depend on master:copyJars but that fails
The below solution
stripped off the tasks which didn't work.
I have only ONE build.gradle file and the settings.gradle file. The settings gradle file is
include 'master', 'toneserver','webserver'
The master build.gradle file is(SPECIFICALLY, search for the two instances of setupAll as somehow there is something wrong with that)
//NOTE: Currently this file is for dependency management only but we would like
// to convert all of the build to gradle from the ant files. We needed to add dependency
// management so did so with gradle first as a first step in the process of evolution
allprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
buildDir = 'output'
task hello << { task -> println "I'm $task.project.name" }
build << { task -> println "MASTER: I'm building now classpath=$sourceSets.main.compileClasspath.files" }
}
project(':toneserver') {
dependencies {
compile fileTree(dir: 'play-1.2.4/framework/lib', include: '*.jar')
compile fileTree(dir: 'play-1.2.4/framework', include: '*.jar')
compile project(':master')
compile project(':webserver')
}
task eclipse(overwrite: true) {
}
}
project(':webserver') {
dependencies {
compile fileTree(dir: 'play-1.2.4/framework/lib', include: '*.jar')
compile fileTree(dir: 'play-1.2.4/framework', include: '*.jar')
compile project(':master')
}
//playframework has it's own generation of .classpath and .project fils so do not
//overwrite their versions
task eclipse(overwrite: true) {
}
}
project(':master') {
project.ext.genLibDir = file('lib')
project.ext.fixedLibDir = file('libother')
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '4.1.4.Final'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.6.6'
compile group: 'org.slf4j', name: 'log4j-over-slf4j', version: '1.6.6'
compile group: 'ch.qos.logback', name: 'logback-core', version: '1.0.6'
compile group: 'joda-time', name: 'joda-time', version: '2.1'
compile group: 'com.google.inject',name: 'guice', version: '3.0'
compile group: 'com.google.protobuf',name: 'protobuf-java', version: '2.4.1'
//to be erased soon
compile group: 'commons-configuration',name:'commons-configuration',version: '1.8'
compile group: 'org.jboss.netty', name: 'netty', version: '3.2.7.Final'
//compile group: 'org.asteriskjava',name: 'asterisk-java', version: '1.0.0.M3'
compile fileTree(dir: project.ext.fixedLibDir, include: '*.jar')
}
task('copyJars') {
ext.collection = files { genLibDir.listFiles() }
delete ext.collection
copy { from configurations.compile into genLibDir }
copy { from fixedLibDir into genLibDir }
}
tasks.setupAll.dependsOn(copyJars)
}
subprojects {
version = 'Developer-Build'
//configurations.compile {
// exclude group: 'javax.jms', module: 'jms'
// exclude group: 'com.sun.jdmk', module: 'jmxtools'
// exclude group: 'com.sun.jmx', module: 'jmxri'
//}
task('setupAll', dependsOn: ['eclipse']) {
description = 'Update jars from remote repositories and then fix eclipse classpath for master project'
}
hello << {println "- I depend on stserver"}
build << { println "subproject:source sets=$sourceSets.main.java.srcDirs" }
}
task release << { println "putting together release" }
//TODO: have a release task AND if version is null when running the release task
//throw an exception telling the user to pass in a version with "./build -Dversion=xxxx"
//The automated build will call the release task with a version number like that
gradle.taskGraph.whenReady {taskGraph ->
if (taskGraph.hasTask(release) && version == 'Developer-Build') {
throw new StopExecutionException("You must specify -Dversion=<some version> to run the release task")
} else {
version = '1.0-SNAPSHOT'
}
}
What is going on with this? Overriding tasks to depend on other stuff should work pretty easily I though(maybe that syntax is still wrong?)
thanks,
Dean
never mind, stupid mistake, forgot my task was in subprojects and should be outside and needed a : as well so new setupAll is outside subprojects and is
task('setupAll', dependsOn: [':master:copyJars', 'eclipse']) {
description = 'Update jars from remote repositories and then fix eclipse classpath for master project'
}

Resources