How to generate Spock reports with Eclipse - eclipse

How do I generate html reports using the spock reports extension (https://github.com/renatoathaydes/spock-reports). I've added the dependency to my build.gradle file which, as far as I can tell, is the only thing I need to do. But when I run my tests on Eclipse I can't find any report appearing anywhere.
Here's my build.gradle file, spock reports dependency are at the end.
apply plugin: 'java-library'
apply plugin: 'groovy'
repositories {
jcenter()
}
dependencies {
api 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.google.guava:guava:22.0'
testImplementation 'org.codehaus.groovy:groovy-all:2.4.11'
testImplementation 'org.spockframework:spock-core:1.0-groovy-2.4'
testImplementation 'junit:junit:4.12'
testCompile( 'com.athaydes:spock-reports:1.3.1' ) {
transitive = false // this avoids affecting your version of Groovy/Spock
}
testCompile 'org.slf4j:slf4j-api:1.7.13'
testCompile 'org.slf4j:slf4j-simple:1.7.13'
}
EDIT: The build.gradle file is wrong.
I generated the build with "gradle init --type java-library --test-framework spock" which worked fine, I added some groovy classes and could run tests successfully on eclipse, but it gave me a "Cannot infer Groovy class path because no Groovy Jar was found on class path [...]" error when I tried to use gradle.build.
I changed the Groovy dependency from "testImplementatiuon" to "compile". It made it so that the project could compile and run tests from the command line. This also generated spock reports.
Running tests on eclipse still doesn't generate test reports.
I build a new project from the command line with this build.gradle file:
apply plugin: 'groovy'
apply plugin: 'java-library'
repositories { jcenter() }
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.11'
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
testCompile( 'com.athaydes:spock-reports:1.3.1' ) {
transitive = false // this avoids affecting your version of Groovy/Spock
}
testCompile 'org.slf4j:slf4j-api:1.7.13'
testCompile 'org.slf4j:slf4j-simple:1.7.13'
}
And copied the same groovy files on it. Then imported the project to eclipse. This one works when I run tests from eclipse (it generates spock reports). I still don't know what the problem was exactly but I guess my issue is solved.

Related

Eclipse is not using gradle dependencies jar during run or debug

I am trying to do basic hibernate task using Gradle project.
Dependency jars are download by Gradle and placed in Project and External Dependencies library.
I don't get any compile time error. But when I try to run or debug the main class in Eclipse, I am getting class not found NoClassDefFoundError.
Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
When I checked the build path, I could see the dependency library is configured with required jars but still eclipse is not using it.
But when I add the jar manually in the build path, I am not getting this exception.
Build.gradle File
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
}
apply plugin: "eclipse"
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:23.0'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
// https://mvnrepository.com/artifact/org.hibernate/hibernate-core
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.3.6.Final'
// https://mvnrepository.com/artifact/com.oracle.jdbc/ojdbc6
runtime group: 'com.oracle.jdbc', name: 'ojdbc6', version: '11.1.0.6.0'
// https://mvnrepository.com/artifact/com.oracle/ojdbc6
runtime group: 'com.oracle', name: 'ojdbc6', version: '11.2.0.4.0-atlassian-hosted'
}
// 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.
jcenter()
mavenCentral()
}
Thanks in advance!!!
I think you should update the classpath with the latest changes in the build file. Eclipse does not do that automatically in all versions.
Go to package explorer, right-click the build.gradle file, then from the context menu select gradle->refresh gradle project.
You can also enable auto sync from the preferences menus, go to gradle, and check the "Automatic Project Synchronization" checkbox.
Remove/comment this dependency and try.
runtime group: 'com.oracle.jdbc', name: 'ojdbc6', version: '11.1.0.6.0'
My Build.gradle:
plugins {
// Apply the java-library plugin to add support for Java Library
id 'java-library'
}
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:23.0'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
// https://mvnrepository.com/artifact/org.hibernate/hibernate-core
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.3.6.Final'
// https://mvnrepository.com/artifact/com.oracle.jdbc/ojdbc6
// runtime group: 'com.oracle.jdbc', name: 'ojdbc6', version: '11.1.0.6.0'
// https://mvnrepository.com/artifact/com.oracle/ojdbc6
runtime group: 'com.oracle', name: 'ojdbc6', version: '11.2.0.4.0-atlassian-hosted'
}
// 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.
jcenter()
}
With the eclipse plugin, there are different build tasks being added:
./gradlew cleanEclipse eclipse

importing dependencies into eclipse using gradle

I've got what appears to be an adequate gradle file but eclipse refuses to recognise the dependancy I'm trying to import (despite refreshing the gradle project after implementing the dependancy)
My gradle file lacks a buildscript{} block but I'm not familar enough with gradle to implement it. My build file was autogenerated by eclipse so I don't see why it'd be an issue.
I'm trying to import "com.intrinio:sdk:0.0.1"
build.gradle:
// Apply the java-library plugin to add support for Java Library
apply plugin: 'java-library'
// 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.
jcenter()
}
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
compile "com.intrinio:sdk:0.0.1"
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:21.0'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
}
I think this is the lib you want to use.
As it's not deployed in a public repository, you have to manually install it. Checkout the project from github and do as below :
Installation
To install the Intrinio Java SDK to your local Maven repository, simply execute:
mvn install
Then, in your gradle file, add mavenLocal() in the repository section and it should just work fine.

IntelliJ "Cannot infer Scala class path..." but Gradle testCompile is correct?

I've got a Spring Boot project building through Gradle that recently saw the addition of some Gatling tests. The Gatlings stuff, which needs Scala support, is all down in src/test/scala. The build.gradle file got a new testCompile dependency to support it and, from a gradle perspective, all is well...
build.gradle
apply plugin: 'scala'
...
dependencies {
...
testCompile "org.scala-lang:scala-library:2.11.1"
testCompile "io.gatling.highcharts:gatling-charts-highcharts:2.2.5"
...
}
The gradle docs suggest that testCompile is all we need here: https://docs.gradle.org/current/userguide/scala_plugin.html
IntelliJ is unhappy with this configuration insisting
Warning:<i><b>root project 'tenderfoot': Unable to build Scala project configuration</b>
Details: org.gradle.api.GradleException: Cannot infer Scala class path because no Scala library Jar was found. Does root project 'tenderfoot' declare dependency to scala-library? Searched classpath: configuration ':compileClasspath'.</i>
If I lift the dependency up from testCompile to compile, the intellij warning goes away, but now my spring boot uber jar thing is unnecessarily bloated.
What's the way out? How do I get IntelliJ to stop Warning on this?
Is this actually an IntelliJ bug?
I ran into this problem also (having to set the dependency manually from IntelliJ).
I "fixed" it by setting the dependency as compileOnly as opposed to compile, this scope does not include the JAR in the final distribution.
The code I use is (please note that my dependency includes Scala as a transitive dependency):
compileOnly("io.gatling.highcharts:gatling-charts-highcharts:$gatlingVersion")

Using Gradle for Scala and ScalaTest (IntelliJ 2016.3.6)

Here is a quick build.gradle file I put together:
apply plugin: 'scala'
apply plugin: 'idea'
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
compile "org.scala-lang:scala-library:2.12.2"
compile "org.scala-lang:scala-compiler:2.12.2"
testCompile 'org.scalatest:scalatest_2.11:3.0.1'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
If understood correctly, when running gradle idea, the external dependencies defined above appear in the External Libraries folder.
While I do see the dependencies in the folder, the issue I am facing is that I am unable to import anything from my external libraries provided by Gradle. Anything I manually provide (i.e. a downloaded version of the Scala SDK) works perfectly fine.
I have src and test marked as my sources root and test sources root, respectively.
What could possibly be the issue? Detailed explanations are also appreciated; I'm coming from a Maven background and struggling with the Gradle documentation.

Gradle: Setting up Scala project with Apache Spark in Eclipse

I am not able to setup a Scala project with Apache Spark dependency in Eclipse. Using a Scala IDE plugin and Gradle plugins in Eclipse. build.gradle project looks like this:
apply plugin: 'scala'
apply plugin: 'eclipse'
repositories{
mavenCentral()
mavenLocal()
}
dependencies{
compile 'org.slf4j:slf4j-api:1.7.5'
compile "org.scala-lang:scala-library:2.11.2"
compile 'com.sparkjava:spark-core:2.3'
testCompile "junit:junit:4.11"
}
task run(type: JavaExec, dependsOn: classes) {
main = 'Main'
classpath sourceSets.main.runtimeClasspath
classpath configurations.runtime
}
Under the Referenced Libraries I can see spark-core-2.3.jar. But I can't import any Spark library into Scala class.
I did try running gradle eclipse command but no luck.
You're referencing the wrong dependency - instead of com.sparkjava:spark-core:2.3 (which belongs to another project, Spark web framework), you should include:
compile 'org.apache.spark:spark-core_2.11:2.0.1'
This uses latest stable version (2.0.1).