According to the official JUnit 5 samples: "https://junit.org/junit5/docs/current/user-guide/#overview-getting-started-example-projects" and "https://github.com/junit-team/junit5-samples/blob/r5.9.1/junit5-jupiter-starter-gradle/build.gradle" the BOM dependency "testImplementation(platform('org.junit:junit-bom:5.9.1'))" should be used:
...
dependencies {
testImplementation(platform('org.junit:junit-bom:5.9.1'))
testImplementation('org.junit.jupiter:junit-jupiter')
}
...
But looking at the Gradle "Use JUnit 5" documentation: "https://docs.gradle.org/current/userguide/java_testing.html#using_junit5" this dependency is missing:
...
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.1'
}
...
Is this a bug or is this done on purpose?
Related
I'm using Gradle's conventions as described here:
https://docs.gradle.org/current/samples/sample_convention_plugins.html
And in the convention plugin, I'm applying a plugin (io.freefair.gradle:lombok-plugin:6.5.1) however I now need to override a dependency that it uses (I need org.projectlombok:lombok:1.18.22 not 1.18.24)
I've tried this:
buildscript {
dependencies {
classpath 'org.projectlombok:lombok:1.18.22'
}
}
plugins {
id 'groovy-gradle-plugin'
}
...
dependencies {
implementation 'io.freefair.gradle:lombok-plugin:6.5.1'
...
implementation 'org.projectlombok:lombok:1.18.22'
}
But version 1.18.24 was used. I've also tried adding this to my build.gradle:
buildscript {
dependencies {
classpath 'org.projectlombok:lombok:1.18.22'
}
}
plugins {
id 'billforward.java-conventions'
}
but still 1.18.24 was used.
As an aside, the two underlying issues I'm trying to solve are:
https://github.com/freefair/gradle-plugins/issues/549 - Resolved in 6.5 of lombok-plugin
https://github.com/projectlombok/lombok/issues/3180 - Broken in 1.18.24 of lombok
The lombok version used by io.freefair.lombok can be customized by using the lombok extension property:
plugins {
id "io.freefair.lombok" version "6.5.1"
}
lombok.version = "1.18.22"
This is documented here: https://docs.freefair.io/gradle-plugins/6.5.1/reference/#_io_freefair_lombok_base
Adding lombok itself to the buildscript classpath (or the runtime classpath of your gradle plugin) will not do anything.
I'm working to get TestFX setup for use on a Gradle project. I followed the directions on https://github.com/TestFX/TestFX/blob/master/README.md but it still seems to give me problems. Any ideas why it isn't finding the method?
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not find method testCompile() for arguments [org.testfx:testfx-core:4.0.16-alpha] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
gradle.build
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.9'
id 'jacoco'
}
repositories {
// Use JCenter for resolving dependencies.
jcenter()
mavenCentral()
}
dependencies {
// Use JUnit Jupiter API for testing.
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2'
// Use JUnit Jupiter Engine for testing.
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
// This dependency is used by the application.
implementation 'com.google.guava:guava:29.0-jre'
// Ikonli Text Icons
implementation 'org.kordamp.ikonli:ikonli-javafx:12.1.0'
implementation 'org.kordamp.ikonli:ikonli-fontawesome5-pack:12.1.0'
implementation 'org.kordamp.ikonli:ikonli-materialdesign2-pack:12.1.0'
implementation 'org.kordamp.ikonli:ikonli-material2-pack:12.1.0'
// TestFX
testCompile "org.testfx:testfx-core:4.0.16-alpha"
testCompile 'org.junit.jupiter:junit-jupiter-api:5.5.1'
testCompile "org.testfx:testfx-junit5:4.0.16-alpha"
testCompile group: 'org.hamcrest', name: 'hamcrest', version: '2.1'
}
application {
// Define the main class for the application.
mainClass = 'App'
}
tasks.named('test') {
// Use junit platform for unit tests.
useJUnitPlatform()
}
javafx {
version = "17"
modules = ['javafx.controls', 'javafx.fxml']
}
jacoco {
.
.
.
Note: I did try changing to plugin{id 'org.openjfx.javafxplugin' version '0.0.8'} and javafx {version = '12'} with no change in behavior.
try with testImplementation I Believe that has replaced testCompile
I'm using Gradle 4.10.2 (but would be fine using the latest version to get it to work). Here's my gradle file:
plugins {
id 'org.springframework.boot' version '2.2.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
jcenter()
}
ext {
set('springCloudVersion', "Hoxton.SR3")
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client'
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
runtime 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
When I execute bootJar, it fails with a lot of errors. The errors are all due to not finding getters, setters, etc. that are auto generated by lombok. How can I resolve the errors? I've seen other posts about this issue and they all recommend adding the lombok dependency as a annotationProcessor & compileOnly but I've already done this and still have this issue.
Update
Here are a couple of errors that I get:
C:\Users\user\eclipse-workspace\example\src\main\java\com\example\proj\service\CarService.java:60: error: cannot find symbol
log.debug("calling for cars {} ", cars);
^
symbol: variable log
location: class CarService
C:\Users\user\eclipse-workspace\example\src\main\java\com\example\proj\service\CarService.java:66: error: cannot find symbol
CarDtoBuilder dtoBuilder = dtoBuilderByCar.getOrDefault(
^
symbol: class CarDtoBuilder
location: class CarService
log should come from annotation #Slf4j. And the CarDtoBuilder is from #Builder(builderMethodName = "hiddenBuild") annotated on CarDto. Both are lombok annotations.
Update 2
Now trying Gradle 4.10.3. Same result. Here's output from gradle -v:
------------------------------------------------------------
Gradle 4.10.3
------------------------------------------------------------
Build time: 2018-12-05 00:50:54 UTC
Revision: e76905e3a1034e6f724566aeb985621347ff43bc
Kotlin DSL: 1.0-rc-6
Kotlin: 1.2.61
Groovy: 2.4.15
Ant: Apache Ant(TM) version 1.9.11 compiled on March 23 2018
JVM: 1.8.0_222 ( 25.222-b10)
OS: Windows 10 10.0 amd64
Update 3
I've tried this using Gradle 6 same result. I've tried using Windows and Mac... same result. I've tried using JDK 11 instead of JDK 8... same result.
Update 4
I'm using #Builder lombok annotation. I wonder if that is causing an issue.
I don't see your lombok-plugin configuration on your build.gradle file.
I had to setup lombok on my project for gradle 4.10.3 and this is what I did:
group 'io.metadata'
version '1.11-SNAPSHOT'
apply plugin: 'java'
project.ext.set("spring.boot.version", "2.2.6.RELEASE")
project.ext.set("spring.core.version", "5.2.5.RELEASE")
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath("io.freefair.gradle:lombok-plugin:5.0.0-rc4")
}
}
subprojects {
repositories {
mavenLocal()
mavenCentral()
}
apply plugin: 'java'
apply plugin: 'io.freefair.lombok'
}
Check the apply plugin: 'io.freefair.lombok' and the dependencies defined for it on buildscript.
Note that I am using multi module project but either way you can use lombok plugin and apply it.
It is not mandatory to use lombok-plugin but it works very well and it's easy to do. You can follow the documentation here:
https://plugins.gradle.org/plugin/io.freefair.lombok
Remove any references to static imports involving code generated by lombok. In my case, I had:
import static com.example.car.dto.CarDto.CarDtoBuilder;
CarDtoBuilder was generated via lombok #Builder on the CarDto class. Once resolved, the other lobmok compile related issues such as log symbol not found (created by #Slf4j) go away.
I'm following the latest SpringBoot gradle plugin reference in order to setup a SpringBoot project that can build a uberjar.
Below is the full content of build.gradle.kts:
plugins {
java
application
id("org.springframework.boot") version "2.2.1.RELEASE"
id("io.spring.dependency-management") version "1.0.8.RELEASE"
}
repositories {
jcenter()
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
testImplementation("org.testng:testng:6.14.3")
}
application {
// Define the main class for the application.
mainClassName = "com.demo.App"
}
val test by tasks.getting(Test::class) {
// Use TestNG for unit tests
useTestNG()
}
dependencyManagement {
imports {
mavenBom(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
}
}
Unfortunately, when I run gradle commands I get the following error:
> Configure project :
e: /Users/xux/Documents/toys/web/build.gradle.kts:15:5: Unresolved reference: providedRuntime
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/xux/Documents/toys/web/build.gradle.kts' line: 15
* What went wrong:
Script compilation error:
Line 15: providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
^ Unresolved reference: providedRuntime
1 error
I'm using Java 1.8.0_201, Gradle 6.0, Kotlin 1.3.50, Mac OS X 10.15.1 x86_64.
I have an app based as follows:
Spring Framework 5.0.4.RELEASE
Gradle 4.7 - multimodule project configured through
JUnit 5.1.1
The configuration about Gradle with JUnit is in the build.gradle file located in the root module:
...
subprojects {
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.junit.platform.gradle.plugin'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
repositories {
jcenter()
}
ext {
...
junitVersion = '5.1.1'
...
}
dependencies {
...
//Testing
...
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
testCompile "org.junit.jupiter:junit-jupiter-params:$junitVersion";
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
....
}
test {
useJUnitPlatform()
}
}
//This location is mandatory
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.junit.platform:junit-platform-gradle-plugin:1.1.0"
}
}
Through Jenkins I execute:
gradle :thymeleaf-02-infrastructure:test --parallel
and with Publish JUnit test result report is configured to thymeleaf-02-infrastructure/build/test-results/junit-platform/*.xml
From above all work fine, I can see in Jenkins the #Test passed but Gradle does not generate the report directory with the expected html file.
Even if directly the gradle :thymeleaf-02-infrastructure:test --parallel command is executed in the terminal, all work (tests passe), but Gradle does not generate the report directory with the expected html file.
I already have read these links:
How to use JUnit 5 with Gradle?
How to create an HTML report for JUnit 5 tests?
And well I am using
test {
useJUnitPlatform()
}
and Gradle is >4.6, 4.7, so what is missing?
You need to remove the org.junit.platform.gradle.plugin because it disables the standard test task by default.