Getting Specs2 to shows results with Gradle - gradle

Having trouble getting Specs2 to work with Gradle, and the examples/advice I'm seeing around the place isn't really helping. The tests appear to be running, it's just that results aren't turning up (neither in the console nor the html report). What am I missing?
All the spec classes are decorated with
#RunWith(classOf[JUnitRunner])
The build.gradle looks as follows (java project, with scala/specs2 tests):
apply plugin: 'java'
apply plugin: 'scala'
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'org.jetbrains:annotations:15.0'
compile 'org.scala-lang:scala-library:2.11.7'
testCompile 'junit:junit:4.5'
testCompile "org.specs2:specs2-core_2.11:3.7.2"
testCompile "org.specs2:specs2-junit_2.11:3.7.2"
testCompile "org.apache.commons:commons-io:1.3.2"
}
repositories {
mavenCentral()
maven {
url "https://oss.sonatype.org/content/repositories/releases"
}
maven {
url "http://dl.bintray.com/scalaz/releases"
}
}
test {
testLogging.showStandardStreams = true
}
test {
onOutput { descriptor, event ->
logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message )
}
}
Based on what I'm reading and my own (admittedly limited) knowledge of gradle, this should work. What am I missing?
Edit:
Updating the specs2 version (changed above) helped.

Related

Gradle Kotlin Native - You have not specified any compilation arguments. No output has been produced

I'm pretty new to Gradle and Kotlin Native. I want to setup my build.gradle so that I can use Native to compile my code. I'm using the Konan plugin to do this. It worked fine when I hard-coded my class in the konanArtifacts.program.srcFiles. But obviously if I add more classes, I'll have to add the paths to srcFiles and I don't (and shouldn't) need to. So I looked around to find a way to add any classes I add automatically, and I attempted sourceSets. But when I try to run the compileKonanClientMingw task now my gradle console gives me the following:
error: you have not specified any compilation arguments. No output has been produced.
I'm not entirely sure that I'm using sourceSets correctly, but this seems to be the farthest I got. Below is my build.gradle
build.gradle:
buildscript {
ext.kotlin_version = '1.2.41'
ext.konan_version = '0.6'
repositories {
mavenCentral()
maven {
url "https://dl.bintray.com/jetbrains/kotlin-native-dependencies"
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-native-gradle-plugin:$konan_version"
}
}
plugins {
id 'java'
}
group 'net.dev909'
version '1.0'
apply plugin: 'kotlin'
apply plugin: 'konan'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
testCompile group: 'junit', name: 'junit', version: '4.12'
}
sourceSets.main.allSource.srcDir '/src/main/kotlin/'
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
konanArtifacts {
program('client-' + version) {
srcFiles sourceSets.main.runtimeClasspath
}
}
Source sets are a part of the Java world and the Java plugin, so the Kotlin/Native plugin avoids using them to be independent on Java. But you still able to compile a bunch of classes, just specify the srcDir parameter:
konanArtifacts {
program('client-' + version) {
srcDir 'src/main/kotlin/'
}
}
Also note that src/main/kotlin/ is a default source path. So if you use only this path, you don't need to specify it explicitly. You may just write:
konanArtifacts {
program('client-' + version)
}

multiple testng test listeners running using gradle test command

I have 2 custom listeners implementing ITestListener, ISuiteListener, IInvokedMethodListener . when I run the command from gradle as gradle clean --test testname . it runs both listeners though I have only one class defined in the #Listeners annotation in test. Its a gradle project but when I run the test in intellij as testng test it runs with only 1 listener as expected. Can you please tell how to make it run with only 1 listener using gradle command
my build.gradle below and testng version I am using is 6.9.4 and I tried 6.9.10 too
ext {
unitTestingMinHeapSize = "512m"
}
// Apply the java plugin to add support for Java
apply plugin: 'java'
// Apply the application plugin to add support for building an application
apply plugin: 'application'
// Apply the eclipse plugin to add support for building on eclipse
apply plugin: 'eclipse'
// Apply the idea plugin to add support for building on IDEA
apply plugin: 'idea'
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
mavenCentral()
mavenLocal()
}
// In this section you declare the dependencies for your production and test code
dependencies {
compile project(':oos')
testCompile project(':oos')
compile "commons-pool:commons-pool:$apacheCommonsPool1Version"
compile "org.apache.commons:commons-lang3:$apacheCommonsLangVersion"
compile "org.apache.commons:commons-pool2:$apacheCommonsPool2Version"
compile "com.rabbitmq:amqp-client:$rabbitMQClientVersion"
compile "redis.clients:jedis:$jedisVersion"
compile "org.apache.httpcomponents:httpclient:$httpClientVersion"
compile "org.apache.httpcomponents:httpmime:$httpmimeversion"
compile "io.rest-assured:rest-assured:$restAssuredVersion"
compile "org.hamcrest:hamcrest-all:$hamcrestVersion"
compile "org.postgresql:postgresql:$postgresqlversion"
compile "com.googlecode.json-simple:json-simple:1.1.1"
compile "com.codepine.api:testrail-api-java-client:1.0.2"
testCompile "org.mockito:mockito-all:$mockitoVersion"
testCompile "org.springframework:spring-test:$springVersion"
compile ("org.testng:testng:$testngVersion") {
exclude group: "junit", module: "junit"
}
testCompile "org.apache.commons:commons-pool2:$apacheCommonsPool2Version"
}
test {
for (String key : System.getProperties().keySet()) {
systemProperty key, System.properties["$key"]
}
jvmArgs "-XX:-UseSplitVerifier"
systemProperty "runId", findProperty("runId")
useTestNG { useDefaultListeners = true }
beforeTest { descriptor ->
logger.lifecycle("Running: " + descriptor)
}
minHeapSize = "$unitTestingMinHeapSize"
jvmArgs '-XX:+UseConcMarkSweepGC', '-XX:+CMSIncrementalMode' //,'-XX:+PrintGCDetails','-XX:+PrintGCTimeStamps'
if (System.getProperty("test.profile", "false").equals("true")) {
jvmArgs "-noverify", "-agentpath:${profilerDir}/lib/deployed/jdk16/mac/libprofilerinterface.jnilib=${profilerDir}/lib,5140,0"
}
// listen to standard out and standard error of the test JVM(s)
onOutput { descriptor, event ->
// logger.lifecycle("Test: " + descriptor + " produced standard out/err: " + event.message )
if (event.destination == TestOutputEvent.Destination.StdErr) {
logger.error(" ERROR: " + event.message.trim())
}
}
}

Building a fully executable Spring Boot 1.3 war from a Gradle multi project build

I'm trying to build a fully executable WAR using Spring Boot 1.3 as per https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html. If I build a single Gradle project, it all works fine, but I havea multi project build, where I have a "root" project and then several projects underneath it, and I cannot get it to build anything but a standard, "fat" WAR file, without the providedRuntime of Jetty and without the scripts to make it run.
Does anyone know how to do this?
In my root project, I have the following (abridged):
buildscript {
repositories {
mavenCentral()
}
ext {
springBootVersion = '1.3.0.RELEASE'
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
}
}
allprojects {
//Put instructions for all projects
repositories {
mavenCentral() // jcenter is missing spring-orm.4.1.6.RELEASE jar file so try mavenCentral first
jcenter {
url "http://jcenter.bintray.com/"
}
maven { url 'http://repo.opensourceagility.com/release' }
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'spring-boot'
}
and then in the subproject which is a web project, and which I'm trying to build, I have:
apply plugin: 'war'
dependencies {
// Include related projects
compile project(':project-model')
compile project(':project-dynamoDB')
// Core Spring Boot - note version is set in main build.gradle file
compile 'org.springframework.boot:spring-boot-starter-web'
// Remove Tomcat (included in -web) and include Jetty instead
providedRuntime 'org.springframework.boot:spring-boot-starter-jetty'
// Other Spring modules
compile 'org.springframework.boot:spring-boot-starter-social-facebook'
compile 'org.springframework.boot:spring-boot-starter-social-linkedin'
compile 'org.springframework.social:spring-social-google:1.0.0.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-thymeleaf'
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.boot:spring-boot-devtools'
compile 'org.springframework:spring-context'
compile 'org.springframework:spring-context-support'
}
configurations {
providedRuntime.exclude group: 'org.springframework.boot', module:'spring-boot-starter-tomcat'
all*.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' // exclude when using log4j
}
springBoot {
mainClass = 'rs.web.Weblication'
executable = true
}
bootRun {
addResources = true
}
processResources {
// exclude resources if they look like they're profile dependent but don't match the current env/profile
eachFile { d ->
if(d.name.endsWith('.xml') || d.name.endsWith('.yaml') || d.name.endsWith('.properties')) {
//def fname = d.name.replaceFirst(~/\.[^\.]+$/, '')
//if(fname.indexOf("-") > -1 && ! fname.endsWith("-" + environment)) {
// d.exclude()
//} else {
// replace #variables# listed below in properties/config files
filter(org.apache.tools.ant.filters.ReplaceTokens, tokens: [
activeProfiles: environment
])
//}
}
}
}
war {
baseName = 'project-web'
version = '1.0.0'
manifest {
attributes 'Implementation-Title': baseName,
'Implementation-Version': version
}
webXml = file('src/main/resources/web.xml')
// rename the war task which has profiles appended from warName-profile,profile2.war
// to warName-profile.profile2.war
classifier = environment.replaceAll(',','-')
}
but when I build it (./gradlew build, or ./gradlew subprojectname:build), all is well and a working WAR is created, but not an executable one.
With a single project, I have it working fine.
Ah ha, right well I build a test multi-project build and it worked OK, so it was clearly the configuration above.
I worked through a process of elimination and it turns out that the problematic area was the line
classifier = environment.replaceAll(',','-')
which is intended to rename files with environment variables as part of the name. This process seems to get in the way of the script addition; perhaps it could be applied afterwards if it's really necessary.

Gradle fails to create Eclipse project files

I am trying to start a new Java EE project with Gradle. I have everything close to the way I want it, and im trying to build the eclipse files. The problem is when i run the command gradle eclipse the eclipse plugin creates the eclipse files for the bottom level project, but not the subprojects.
my folders look like this
foobar
--ear
--ejb
--spring
--web
build.gradle
settings.gradle
even if i do gradle ejb:eclipse everything appears to run correctly, i get the notices that the eclipse tasks ran in the console, but no files in the ejb project.
here is my build.gradle. What am i doing wrong?
configure(allprojects){ project ->
apply plugin: 'java'
apply plugin: 'eclipse'
sourceCompatibility = 1.6
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: "C:/IBM/WebSphere/AppServer/8.5/plugins/", include: [
'com.ibm.ws.runtime.jar',
'com.ibm.ws.wsadie/marshall.jar'
])
compile fileTree(dir: "C:/IBM/WebSphere/AppServer/8.5/runtimes/", include: [
'com.ibm.jaxrs.thinclient_8.5.0.jar',
'com.ibm.jaxws.thinclient_8.5.0.jar',
'com.ibm.ws.ejb.embeddableContainer_8.5.0.jar',
'com.ibm.ws.ejb.thinclient_8.5.0.jar',
'com.ibm.ws.jpa.thinclient_8.5.0.jar',
'com.ibm.ws.orb_8.5.0.jar'
])
}
ext {
easymockVersion = '3.3.1'
jeeVersion = '6.0'
junitVersion = '4.12'
springVersion = '4.1.5.RELEASE'
swaggerVersion = '1.3.12'
}
}
project('ear'){
description = "The EAR Project"
apply plugin: 'ear'
dependencies {
deploy project(':ejb')
deploy project(':spring')
deploy project(path: ':web', configuration: 'archives')
}
}
project('ejb'){
description = "The EJB Project"
dependencies {
compile project(':spring')
}
}
project('spring'){
description = "The Spring BL Logic"
dependencies {
runtime "org.springframework:spring-jdbc:$springVersion"
testCompile "junit:junit:$junitVersion"
testCompile "org.easymock:easymock:$easymockVersion"
testCompile "org.springframework:spring-test:$springVersion"
}
}
project('web'){
description = "The REST layer"
apply plugin: 'war'
dependencies {
compile project(':ejb')
runtime "com.wordnik:swagger-annotations:$swaggerVersion"
runtime "com.wordnik:swagger-core_2.10:$swaggerVersion"
runtime "com.wordnik:swagger-jaxrs_2.10:$swaggerVersion"
}
}
This is the output i get. It tells me the plugin fired for the subprojects but i can't figure out why it doesn't create any files
$ gradle eclipse
:eclipseClasspath
:eclipseJdt
:eclipseProject
:eclipse
:ear:eclipseClasspath
:ear:eclipseJdt
:ear:eclipseProject
:ear:eclipse
:ejb:eclipseClasspath
:ejb:eclipseJdt
:ejb:eclipseProject
:ejb:eclipse
:spring:eclipseClasspath
:spring:eclipseJdt
:spring:eclipseProject
:spring:eclipse
:web:eclipseClasspath
:web:eclipseJdt
:web:eclipseProject
:web:eclipse

Spring-Boot html in /templates don't render from command line

I have read several online posts about this issue, but for some reason none of those helped me solve this. I looked at the spring-boot examples and I don't think I am doing much different than those.
I am using Spring-boot 1.2.1, Thymeleaf, embedded tomcat without issue in IntelliJ. However, when I do a "gradle clean build", move the jar file, and an application.properties file to a deploy directory. I then start on the command with:
java -jar edm-0.1.0.jar
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/loginPage", template might not exist or might not be accessible by any of the configured Template Resolvers
at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:245)
I am letting spring-boot configure my site for the most part. I am using the recommended directory structure:
I can hit the index page, and the REST calls seem to work just fine.
UPDATE based upon feedback:
I don't know if this is a broken jar issue, but when I extract it the structure and files appear correct. I can run "gradle bootRun" from the top of my project structure just fine. But if I deploy the jar file and run it, I get an error:
Task 'bootRun' not found in root project 'edm'
Here is my build.gradle file in case there might be an issue in it:
apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'jacoco'
apply plugin: 'maven'
idea {
project {
//if you want to set specific jdk and language level
jdkName = '1.8'
languageLevel = '1.8'
}
}
jacoco {
toolVersion = "0.7.0.201403182114"
}
project.ext {
springBootVersion = '1.2.1.RELEASE'
}
configurations {
querydslapt
}
buildscript {
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
maven { url "http://repo.spring.io/libs-milestone" }
maven { url "http://repo.spring.io/libs-snapshot" }
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
}
}
jar {
baseName = 'edm'
version = '0.1.0'
}
dependencies {
querydslapt group: 'com.mysema.querydsl', name: 'querydsl-jpa', version: '2.8.0', classifier: 'apt-one-jar', transitive: false
compile("org.springframework.boot:spring-boot-starter-web:$springBootVersion")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-security")
compile("org.springframework.boot:spring-boot-starter-data-jpa:$springBootVersion")
compile("org.springframework.security:spring-security-web:4.0.0.M1")
compile("org.springframework.security:spring-security-config:4.0.0.M1")
compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity3:2.1.1.RELEASE')
compile('com.android.tools.build:gradle:1.0.1')
compile("org.hibernate:hibernate-core:4.3.4.Final")
compile("org.hibernate:hibernate-entitymanager:4.3.4.Final")
compile("org.hibernate:hibernate-validator")
compile("org.apache.velocity:velocity:1.7")
compile('javax.mail:mail:1.4.1')
compile("org.springframework:spring-context-support")
compile("com.h2database:h2:1.3.172")
compile("joda-time:joda-time:2.3")
compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.5.0")
compile("org.codehaus.groovy.modules.http-builder:http-builder:0.7.1")
compile('org.codehaus.groovy:groovy-all:2.2.1')
compile('org.jadira.usertype:usertype.jodatime:2.0.1')
compile("postgresql:postgresql:9.1-901.jdbc4")
testCompile('org.spockframework:spock-core:1.0-groovy-2.0-SNAPSHOT') {
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
}
testCompile('org.spockframework:spock-spring:1.0-groovy-2.0-SNAPSHOT') {
exclude group: 'org.spockframework', module: 'spock-core'
exclude group: 'org.spockframework', module: 'spring-beans'
exclude group: 'org.spockframework', module: 'spring-test'
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
}
testCompile("org.springframework.boot:spring-boot-starter-test:$springBootVersion")
testCompile('org.codehaus.groovy.modules.http-builder:http-builder:0.7+')
testCompile("junit:junit")
// for the anontation processor
querydslapt group: 'com.mysema.querydsl', name: 'querydsl-jpa', version: '2.8.0', classifier: 'apt-one-jar', transitive: false
// for compiling
compile("com.mysema.querydsl:querydsl-jpa:3.3.3")
compile("com.mysema.querydsl:querydsl-apt:3.3.3")
}
task wrapper(type: Wrapper) {
gradleVersion = '2.0'
}
project.configurations {
providedRuntime
}
project.bootRepackage {
enabled = true
}
I also tried adding some thymeleaf configuration (even though I am not explicitly using Thymeleaf) to my application.properties file:
liquibase.changeLog=classpath:/db/changelog/db.changelog-master.xml
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.check-template-location=true
So I guess my question is, why does running the "java -jar" not let me view the webpages?
It turns out that my REST controllers were proceeded by "/" so login page became "//loginPage" and that was causing the problem. I found the answer here but it took me a while to realize that was the issue. Hopefully this answer will help out someone in the future as it as a bear to figure out.

Resources