Conflict org.springframework.boot.test.context.SpringBootTest; and org.springframework.test.context.junit.jupiter.SpringExtension; - junit

I'm developing a spring boot app.
In my build.gradle I have added the dependency:
compile group: 'org.springframework', name: 'spring-test', version: '3.1.1.RELEASE'
implementation group: 'commons-io', name: 'commons-io', version: '2.6'
to use MockMultipartFile in my service:
import org.springframework.mock.web.MockMultipartFile;
...
...
MultipartFile multipartFile = new MockMultipartFile("file",
file.getName(), "image/jpeg", IOUtils.toByteArray(input));
But now in the testing class I have this error:
This is my build.gradle:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
compile 'org.hibernate:hibernate-core:5.2.11.Final'
compile 'org.hibernate:hibernate-entitymanager:5.2.11.Final'
compile 'mysql:mysql-connector-java'
compile 'org.apache.commons:commons-dbcp2:2.0.1'
compile 'javax.xml.bind:jaxb-api:2.3.1'
compile 'com.sun.xml.bind:jaxb-core:2.3.0'
compile 'com.sun.xml.bind:jaxb-impl:2.3.1'
compile 'javax.activation:activation:1.1.1'
compileOnly('org.projectlombok:lombok')
annotationProcessor 'org.projectlombok:lombok'
testCompile 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
testCompile('org.mockito:mockito-junit-jupiter:2.23.0')
compile 'org.modelmapper:modelmapper:2.3.0'
compile 'com.google.firebase:firebase-admin:6.13.0'
compile group: 'org.springframework', name: 'spring-test', version: '3.1.1.RELEASE'
implementation group: 'commons-io', name: 'commons-io', version: '2.6'
}

You use a quite old version of Spring Test:
compile group: 'org.springframework', name: 'spring-test', version: '3.1.1.RELEASE'
I assume Spring Test 3.1.1 did not yet have the JUnit JUpiter SpringExtension. Either update spring-test to a more recent version or remove it from your build.gradle and let Spring Boot with the Spring Boot Starter Test manage the dependency version of spring-test.
So your updated dependencies section could look like the following:
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'
// this is your testing swiss-army knife - take a look at its transitive dependency
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
compile 'org.hibernate:hibernate-core:5.2.11.Final'
compile 'org.hibernate:hibernate-entitymanager:5.2.11.Final'
compile 'mysql:mysql-connector-java'
compile 'org.apache.commons:commons-dbcp2:2.0.1'
compile 'javax.xml.bind:jaxb-api:2.3.1'
compile 'com.sun.xml.bind:jaxb-core:2.3.0'
compile 'com.sun.xml.bind:jaxb-impl:2.3.1'
compile 'javax.activation:activation:1.1.1'
compileOnly('org.projectlombok:lombok')
annotationProcessor 'org.projectlombok:lombok'
// REMOVE (managed by Spring Boot Starter Test) testCompile 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
// REMOVE (managed by Spring Boot Starter Test) testCompile('org.mockito:mockito-junit-jupiter:2.23.0')
compile 'org.modelmapper:modelmapper:2.3.0'
compile 'com.google.firebase:firebase-admin:6.13.0'
// REMOVE compile group: 'org.springframework', name: 'spring-test', version: '3.1.1.RELEASE'
implementation group: 'commons-io', name: 'commons-io', version: '2.6'

Related

JUnitException: TestEngine with ID 'spock' failed to discover tests

We are attempting to make some updates to our testing suite. We would like to convert our contract tests that use PACT to use jUnit5.
When we update our packages such as our PACT consumer/provider and attempt to run the code we get this exception :
org.gradle.api.internal.tasks.testing.TestSuiteExecutionException: Could not complete execution for Gradle Test Executor 8.
...
Caused by: org.junit.platform.commons.JUnitException: TestEngine with ID 'spock' failed to discover tests
The current build.gradle file contains
plugins {
id 'java'
id 'groovy'
id "au.com.dius.pact" version '4.2.13'
}
dependencies {
testImplementation 'org.codehaus.groovy:groovy:3.0.12'
testImplementation group: 'au.com.dius.pact.consumer', name: 'junit5', version: '4.3.4'
testImplementation group: 'au.com.dius.pact.provider', name: 'junit5', version: '4.3.4'
testImplementation 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1'
testImplementation 'com.motorolasolutions.pnf:utils:1.0.+:test-lib'
testImplementation "org.spockframework:spock-core:2.1-M2-groovy-3.0"
testImplementation "org.spockframework:spock-spring:2.1-M2-groovy-3.0"
testImplementation "org.spockframework:spock-core:2.1-M2-groovy-3.0"
testImplementation('com.athaydes:spock-reports:2.1.1-groovy-3.0') {
transitive = false
}
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: '5.9.1'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.9.1'
}
We have tried messing with the plugin Id for 'groovy' and 'java' without luck. Does anyone have any recommendations on this issue?
Thanks

Can't Set Up MySQL Connection: CLIENT_PLUGIN_AUTH is required

was trying to connect to mysql server with spring boot but getting this error: com.mysql.cj.exceptions.UnableToConnectException: CLIENT_PLUGIN_AUTH is required
application.properties:
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=shafin
spring.datasource.password=admin
spring.datasource.driver-class-name =com.mysql.jdbc.Driver
spring.jpa.show-sql: true
i am using sqlyog and wamp server.
gradle.build file:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.boot:spring-boot-starter-validation'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
runtimeOnly 'mysql:mysql-connector-java'
}
i am giving all required authentication info correctly, still getting this error.

I have been trying to upgrade grails to 4.0.7 but I get an error when running the application

The upgrade is from 3.3.10 to 4.0.7 I have followed the upgrade notes but as far as I understand spring has an issue with this plugin "org.grails.plugins.views-json" . I used a lot of json in the project so cannot just remove the plugin.
This is the error i am getting when the application run fails.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jsonSmartViewResolver': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [grails.plugin.json.view.mvc.JsonViewResolver]: Constructor threw exception; nested exception is java.lang.AbstractMethodError
Please let me know if you have any ideas.
Thanks
Here's the build.gradle
buildscript {
repositories {
mavenLocal()
maven { url "http://artifactory.xxxxxx.xxxx.xxxx.xx/xxx/xx" }
maven { url "https://repo.xxxxx.xxxx/xxxxxx" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion" //4.0.7
classpath "gradle.plugin.com.energizedwork:idea-gradle-plugins:1.4"
classpath "org.grails.plugins:hibernate5:${gormVersion - ".RELEASE"}" //7.0.2
classpath "org.grails.plugins:views-gradle:2.1.0.M1"
classpath "net.saliman:gradle-cobertura-plugin:2.6.1"
}
}
version "1.1.2-" + System.getenv("CI_PIPELINE_ID") // Sprint 18
group "xxxxxxx"
apply plugin: "eclipse"
apply plugin: "idea"
apply plugin: "war"
apply plugin: "org.grails.grails-web"
apply plugin: 'org.grails.grails-gsp'
apply plugin: "org.grails.grails-doc"
apply plugin: "org.grails.plugins.views-json"
apply plugin: 'codenarc'
apply plugin: "net.saliman.cobertura"
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
repositories {
mavenLocal()
maven { url "http://artifactory.xxxxxx.xxxx.xxxx.xx/xxx/xx" }
maven { url "https://repo.xxxxx.xxxx/xxxxxx" }
}
configurations {
all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
dependencies {
def VERSION = 'xxxxx-xxxxxx-2.0.0-xxxxxxxxx'
developmentOnly("org.springframework.boot:spring-boot-devtools")
//XXXXXX dependencies
compile group: 'xxx.xxxxx.xxx.xxxxxx', name: 'xxxxxx-xxx-api', version: VERSION, changing: true
compile group: 'xxx.xxxxx.xxx.xxxxxx', name: 'xxxxxx-xxxxxx', version: VERSION, changing: true
compile group: 'xxx.xxxxx.xxx.xxxxxx', name: 'xxxxxx-xxxxxx', version: VERSION, changing: true
compile 'xxx.xxxx.xxx.xxxxxx.xxxxxxxx:xxxxxxxxxxx-client:1.4.0'
compile 'xxx.xxxxx.xxx.xxxxx.plugins3:xxxxxx-xxxxx:2.1.0'
compile 'xxx.xxxxxx.xxxx.xxxxx.xxxx:xxx-rest-client:1.3.0'
//Additional dependencies
compile 'org.grails.plugins:spring-security-core:4.0.3'
compile 'org.grails.plugins:spring-security-rest:3.0.1'
compile 'org.grails.plugins:mail:3.0.0'
compile 'org.grails.plugins:gsp:4.1.0.M3'
compile 'org.awaitility:awaitility:3.1.6'
compile 'org.postgresql:postgresql:42.2.6'
compile 'software.amazon.awssdk:sns:2.7.31'
// Jobs
compile 'org.quartz-scheduler:quartz:latest.release'
compile 'org.grails.plugins:quartz:latest.release'
// initial dependencies
compile "org.grails:grails-datastore-gorm-rest-client:6.0.0.M1"
compile "org.grails:grails-web-common"
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-plugin-url-mappings"
compile "org.grails:grails-plugin-rest"
compile "org.grails:grails-plugin-codecs"
compile "org.grails:grails-plugin-interceptors"
compile "org.grails:grails-plugin-services"
compile "org.grails:grails-plugin-datasource"
compile "org.grails:grails-plugin-databinding"
compile "org.grails:grails-web-boot"
compile "org.grails:grails-logging"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:async"
compile "org.grails.plugins:events"
compile "org.grails.plugins:hibernate5"
compile "org.hibernate:hibernate-ehcache"
compile "org.hibernate:hibernate-core:5.4.0.Final"
compile "org.grails.plugins:views-json:2.1.0.M1"
//compile "org.grails.plugins:views-json-templates"
compile "org.codehaus.groovy.modules.http-builder:http-builder:0.7"
console "org.grails:grails-console"
//compile "org.grails:grails-datastore-rest-client-6.1.12.RELEASE"
profile "org.grails.profiles:rest-api"
profile 'org.grails.profiles:web'
runtime "org.glassfish.web:el-impl:2.1.2-b05"
runtime "com.h2database:h2"
runtime "org.apache.tomcat:tomcat-jdbc"
//runtime "org.grails.plugins:views-json:2.0.2"
//runtime "org.springframework.boot:spring-boot-properties-migrator"
testCompile "org.grails.plugins:geb"
testCompile "org.grails:grails-gorm-testing-support"
testCompile "org.grails:grails-web-testing-support"
compile 'cglib:cglib-nodep:3.2.12'
compile 'org.codehaus.jackson:jackson-core-asl:1.8.3'
compile 'org.codehaus.jackson:jackson-mapper-asl:1.8.3'
}
bootRun {
jvmArgs('-Dspring.output.ansi.enabled=always')
sourceResources sourceSets.main
}
war {
archiveName 'xxxxxxx.war'
}
codenarc {
toolVersion = "1.4"
}
codenarcMain {
configFile = file( 'config/codenarc/codenarcMain.groovy' )
}
codenarcTest {
configFile = file( 'config/codenarc/codenarcTest.groovy' )
}
task codenarcAll {
group = 'other'
description = 'Runs all the codenarc checks'
dependsOn(codenarcTest, codenarcMain)
}
cobertura {
coverageFormats = ['html']
coverageIgnoreTrivial = true
}
// TODO not sure what to do about this. Needs to be 'true' for running locally. Needs to be false for building war.
// TODO Could create a new build-war target which turns it off.
grails.pathingJar = true
There is an incompatibility between 'org.grails.plugins:spring-security-core:4.0.3' and 'org.grails.plugins:spring-security-rest:3.0.1'
Better use older versions :‘org.grails.plugins:spring-security-core:3.2.0’ and ‘org.grails.plugins:spring-security-rest:2.0.0.M2’ -that means that you may review your grails version - while the issue being resolved.

Could not find powermock-api-support-sources.jar during testCompileJava

While running tests in my project, I am getting the following error. We are unsure why the build is looking for source jar files.
04:15:21 > Task :clean UP-TO-DATE
04:15:28 > Task :compileJava FROM-CACHE
04:15:28 > Task :processResources
04:15:28 > Task :classes
04:15:31 > Task :bootWar
04:15:31 > Task :war SKIPPED
04:15:31 > Task :assemble
04:15:32 > Task :checkstyleMain FROM-CACHE
04:15:32 > Task :compileTestJava FAILED
04:15:32
04:15:32 FAILURE: Build failed with an exception.
04:15:32
04:15:32 * What went wrong:
04:15:32
Execution failed for task ':compileTestJava'.
04:15:32 > Could not resolve all files for configuration ':testCompileClasspath'.
04:15:32 > Could not find powermock-api-support-sources.jar (org.powermock:powermock-api-support:2.0.2).
04:15:32 Searched in the following locations:
04:15:32 file:/data/jenkins/.m2/repository/org/powermock/powermock-api-support/2.0.2/powermock-api-support-2.0.2-sources.jar
04:15:32 > Could not find powermock-core-sources.jar (org.powermock:powermock-core:2.0.2).
04:15:32 Searched in the following locations:
04:15:32 file:/data/jenkins/.m2/repository/org/powermock/powermock-core/2.0.2/powermock-core-2.0.2-sources.jar
04:15:32 > Could not find powermock-reflect-sources.jar (org.powermock:powermock-reflect:2.0.2).
04:15:32 Searched in the following locations:
04:15:32 file:/data/jenkins/.m2/repository/org/powermock/powermock-reflect/2.0.2/powermock-reflect-2.0.2-sources.jar
04:15:32
04:15:32 * Try:
04:15:32 Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
I am copying the dependencies.gradle snippet
compile 'org.apache.maven.plugins:maven-surefire-plugin:2.22.0'
testImplementation "org.junit.jupiter:junit-jupiter-api:5.3.0"
testCompile 'org.junit.jupiter:junit-jupiter-params:5.2.0'
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.3.0"
testImplementation group: 'org.mockito', name: 'mockito-core', version: '2.23.4'
testImplementation 'org.mockito:mockito-junit-jupiter:2.23.4'
testCompile group: 'org.powermock', name: 'powermock-mockito-release-full', version: '1.6.4'
testCompile group: 'org.powermock', name: 'powermock-api-support', version: '2.0.0'
testCompile group: 'org.powermock', name: 'powermock-reflect', version: '2.0.0'
testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.0'
I am using java 11 ,springboot 2.0.5 and junit 5
After a lot of trial and error, we found that this is because one of the powermock libraries is still referring to junit 4, and it added some unwanted dependencies. So, we cleaned up the test dependencies, also avoided the libs that have PowerMockRunner. And that fixed the issue. Please find the latest dependencies.gradle snippet below,
testCompile(group: 'org.springframework.boot', name: 'spring-boot-test', version: springBootVersion) {
exclude (module: 'junit')
}
testCompile group: 'org.springframework', name: 'spring-test', version: springVersion
testCompile(group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion) {
exclude(module: 'commons-logging')
}
compile 'org.apache.maven.plugins:maven-surefire-plugin:2.22.0'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.3.2'
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.3.2'
testRuntimeOnly group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.3.2'
testCompile group: 'org.mockito', name: 'mockito-core', version: '2.23.4'
testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.0'

Liferay 7 Json WS External JAR

I have a osgi module (service-builder) to create a WS Json.
My Bnd.Bnd File is Like:
Bundle-Name: Dummy-service
Bundle-SymbolicName: Dummy.service
Bundle-Version: 1.0.0
Bundle-ClassPath:\
.,\
lib/joda-time.jar
-includeresource:\
lib/joda-time.jar=lib/joda-time-2.8.1.jar
Liferay-Require-SchemaVersion: 1.0.0
Liferay-Service: true
My build.gradle :
dependencies
{
compile group: "biz.aQute.bnd", name: "biz.aQute.bndlib", version: "3.1.0"
compile group: "com.liferay", name: "com.liferay.osgi.util", version:
"3.0.0"
compile group: "com.liferay", name: "com.liferay.portal.spring.extender",
version: "2.0.0"
compile group: "com.liferay.portal", name: "com.liferay.portal.kernel",
version: "2.6.0"
compile group: "com.liferay", name: liferay.dynamic.data.mapping.api",
version: "3.5.4"
compile group: "com.liferay", name: "com.liferay.journal.api", version:
"2.6.1"
compile project(":modules: DummyApi: DummyApi-api")
compile group: 'joda-time', name: 'joda-time', version: '2.8.1'
}
buildService {
apiDir = "../Dummy-api/src/main/java"
}
group = "DummyEventApi"
When i generate de jar of the service and explode it, i have correctly the jar in the lib folder, but when i deploy the service i got the following error:
.service [515]_ Unresolved requirement: Import-Package: org.joda.convert_
I read (and based the code) in David article:
https://web.liferay.com/web/user.26526/blog/-/blogs/osgi-module-dependencies
I choosed the option 4, but when i deploy the service allways got the error, and if i remove the code from joda-time the service starts correctly.
Can somewone help ?
The answer is in this thread of liferay community:
https://web.liferay.com/community/forums/-/message_boards/message/89485697