I am using spring-boot and gradle. I want to use latest selenium version, however half of compile dependencies, including drivers, are somehow 3.14 version. I tried invalidating caches, ./gradlew clean build, ./gradlew build --refresh-dependencies, but it doesn't help. My older project has the same dependencies (but no spring-boot) and I this issue is not present.
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
plugins {
id 'org.springframework.boot' version '2.6.7'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
}
group = 'xxx.xxxxxx'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
implementation 'org.seleniumhq.selenium:selenium-java:4.1.4'
// https://mvnrepository.com/artifact/org.testng/testng
testImplementation 'org.testng:testng:7.5'
// https://mvnrepository.com/artifact/io.rest-assured/rest-assured
testImplementation 'io.rest-assured:rest-assured:4.5.1'
// https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager
implementation 'io.github.bonigarcia:webdrivermanager:5.1.1'
// https://mvnrepository.com/artifact/com.github.javafaker/javafaker
implementation 'com.github.javafaker:javafaker:1.0.2'
// https://mvnrepository.com/artifact/org.assertj/assertj-core
testImplementation 'org.assertj:assertj-core:3.22.0'
}
test {
useTestNG()
testLogging {
exceptionFormat(TestExceptionFormat.FULL)
}
systemProperties(System.getProperties())
}
Spring Boot manages the versions for Selenium, so in your case you only specified the version for selenium-java, all other versions were managed by Spring Boot. To properly update all Selenium dependencies, you have to override the property for the Selenium version:
ext['selenium.version'] = '4.1.4'
and remove the version from the selenium-java entry:
implementation 'org.seleniumhq.selenium:selenium-java'
You can find all available properties for libraries managed by Spring Boot in the documentation: https://docs.spring.io/spring-boot/docs/2.6.7/reference/htmlsingle/#appendix.dependency-versions.properties
Related
I am trying to add open api documentation to springboot base REST api project that I have.
It works fine when run locally inside intelliJ IDE or with gradlew run/bootRun
But when the project is packaged as a fat jar using gradlew shadow plugin 'com.github.johnrengelman.shadow' and run on command line as java -jar build/libs/Application-0.0.1-SNAPSHOT-all.jar it fails with ApplicationContextException
Exception stacktrace:
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:205) ~[Application-0.0.1-SNAPSHOT-all.jar:?]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:177) ~[Application-0.0.1-SNAPSHOT-all.jar:?]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:158) ~[Application-0.0.1-SNAPSHOT-all.jar:?]
... 9 more
build.gradle
plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'application'
id 'com.github.johnrengelman.shadow' version "6.0.0"
}
application {
mainClassName = 'com.example.Application'
executableDir = 'lib/'
}
dependencies {
implementation 'org.springdoc:springdoc-openapi-ui:1.5.12'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation files( "lib/$JarV2" )
compileOnly 'org.projectlombok:lombok:1.18.22'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
implementation 'org.slf4j:slf4j-api:1.7.32'
implementation 'org.springframework.boot:spring-boot-starter-validation:2.3.3.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-log4j2:2.4.2'
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.14.0'
implementation 'org.apache.logging.log4j:log4j-api:2.14.0'
implementation 'org.apache.logging.log4j:log4j-core:2.14.0'
implementation 'org.slf4j:jul-to-slf4j:1.7.30'
implementation 'commons-lang:commons-lang:2.6'
implementation "com.moandjiezana.toml:toml4j:0.7.2"
implementation "io.jsonwebtoken:jjwt-api:$jwtVersion"
runtimeOnly "io.jsonwebtoken:jjwt-impl:$jwtVersion"
runtimeOnly "io.jsonwebtoken:jjwt-jackson:$jwtVersion"
implementation 'com.auth0:java-jwt:3.18.1'
implementation 'com.auth0:jwks-rsa:0.19.0'
testImplementation('org.springframework.boot:spring-boot-starter-test')
}
Without the openapi dependency
implementation 'org.springdoc:springdoc-openapi-ui:1.5.12'
standalone run java -jar build/libs/Application-0.0.1-SNAPSHOT-all.jar works absolutely fine.
Is there some dependency conflict between open api and springboot libs ?
Turns out to be known issue and can be solved by including following in build.gradle
import com.github.jengelman.gradle.plugins.shadow.transformers.*
shadowJar {
zip64 true
exclude 'META-INF/*.SF'
exclude 'META-INF/*.DSA'
exclude 'META-INF/*.RSA'
// Required for Spring
mergeServiceFiles()
transform(AppendingTransformer) { resource = 'reference.conf' }
transform(AppendingTransformer) { resource = 'META-INF/spring.handlers' }
transform(AppendingTransformer) { resource = 'META-INF/spring.schemas' }
transform(AppendingTransformer) { resource = 'META-INF/spring.tooling' }
transform(PropertiesFileTransformer) {
paths = ['META-INF/spring.factories' ]
mergeStrategy = "append"
}
}
source: https://github.com/spring-projects/spring-boot/issues/1828
Helo! Sorry for my English, but it's not my native language. I'm trying to make a project to practice webflux and I can't get Swagger to work. I did a good search on StackOverflow and Google and couldn't find a solution. I also tried looking in the SpringFox documentation, but maybe I didn't quite understand. I decided to ask my first question to StackOverflow:
What is missing from my project settings to make Swagger work?
build.gradle root:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:2.1.9.RELEASE"
}
}
plugins {
id "application"
id 'java'
id 'org.springframework.boot' version '2.1.9.RELEASE'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id "io.freefair.lombok" version "5.1.0"
}
dependencies {
compile project(":contract")
}
mainClassName = 'com.pocwebflux.PocWebfluxApplication'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
jcenter()
}
allprojects {
apply plugin: 'java'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'io.freefair.lombok'
apply plugin: 'org.springframework.boot'
group = 'com.example'
version = "1.0.0-SNAPSHOT"
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
}
test {
useJUnitPlatform()
}
dependencyManagement {
imports {
mavenBom "org.springframework.boot:spring-boot-dependencies:2.1.9.RELEASE"
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation "io.springfox:springfox-boot-starter:3.0.0"
compile 'io.springfox:springfox-swagger-ui:3.0.0'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'io.projectreactor:reactor-test'
testImplementation 'org.mockito:mockito-junit-jupiter'
testImplementation 'org.junit.jupiter:junit-jupiter-engine'
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testImplementation 'org.junit.jupiter:junit-jupiter-engine'
testImplementation 'org.junit.jupiter:junit-jupiter-params'
}
test {
useJUnitPlatform()
}
}
build.gradle contract layer:
dependencies {
implementation project(':impl')
}
impl layer: nothing
I still don't have anything implementing just a controller with a test endpoint, just to see if the swagger was working:
ClientController
I created this class following the documentation, but I'm not sure where to use it:
SwaggerUiWebFluxConfigurer
What would be missing from the settings?
Could someone please clarify my question? Thank you very much.
I forgot to say that the build project normally and the service goes up and returns 200 in Postman.
After a series of tries and researches, I found that my problem was with Intellij. I had a cash problem, and I wasn't downloading the dependencies. I did a ./gradlew clean, deleted all springfox and swagger libraries. I went to the root of the project and deleted the ".idea" folder. I downloaded the dependencies again and it includes this:
implementation group: 'org.springframework.plugin', name: 'spring-plugin-core', version: '2.0.0.RELEASE'
Done!
Now it's working.
When trying to add spring-boot-starter-data-jpa to my project through gradle, it just doesn't do it. The #Entity tag doesn't work and the jar doesn't appear in the project and external dependencies folder. There's no error unless I put in the #Entity tag. Here is my gradle file for reference.
plugins {
id 'org.springframework.boot' version '2.3.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
group = 'com.Hype'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '14'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version:
'2.3.4.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-data-rest'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-web-services'
implementation 'org.springframework.session:spring-session-jdbc'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'mysql:mysql-connector-java'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'org.springframework.security:spring-security-test'
}
test {
useJUnitPlatform()
}
Before anyone mentions it, yes I've tried cleaning and rebuilding the project multiple times.
If you are using Gradle 6.x, the compile configuration has been deprecated. Its use has been discouraged since Gradle 3.4. You should use implementation instead. This change would also make this dependency more consistent with the others in your build script. You can learn a bit more about this in the Gradle documentation.
You've also specified a version on the spring-boot-starter-data-jpa dependency. This isn't necessary as the version can be determined by the version of the Spring Boot plugin that you've applied. This is what's happening with the other dependencies in your script where no version is declared. It makes it easier to keep all of the versions in sync.
In short, try updating the dependency declaration to look like the following:
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
SOLVED: The issue was in Spring tool suite, using Project->Clean wasn't updating gradle dependencies. Had to right click build.gradle->gradle->refresh gradle project to get everything to update.
Following the previous suggestion, in the VS Code cleaning Java project helped me to resolve the issue:
Open "Java Project" view -> "..." -> "Clean Workspace"
Depending on VS Code configuration, after the cleaning, the gradle rebuilds dependencies automatically. If not, you can right-click on build.gradle and select "Update Project"
I'm working on small spring boot project using gradle and intellij idea.
After I created a project and restarted intellij idea build.gradle file contents became gray.
But despite this it runs well and I don't get any compilation errors.
Intellij Idea Ultimate version 2019.3.1, java 8, gradle 6.0.1, spring boot 2.1.7
The code of build.gradle is below.
plugins {
id 'org.springframework.boot' version '2.1.7.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
repositories {
maven { url 'https://maven.aliyun.com/repository/public/' }
mavenCentral()
}
dependencies {
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
I've tried to restart Idea again. It didn't help. Then I've tried to use an older version of gradle but everything remains as before.
Issue
The Java/Kotlin application runs as expected in from the Main Class in IntelliJ's IDE. However, when the app is built into a .Jar file the following error occurs: java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.
This is an issue with refactoring the directory, module, root project, and/or group names.
Reproducing Error
I've moved the project to a new directory path and everything runs as expected. However, after I attempt to modify the directory, and/or module names and refactor the rootProject.name in settings.gradle and the group in the build.gradle is when the error above appears when running a new .jar build.
Full Error Message
Exception in thread "Timer-0" java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;
at io.grpc.internal.ClientCallImpl.<init>(ClientCallImpl.java:96)
at io.grpc.internal.ManagedChannelImpl$RealChannel.newCall(ManagedChannelImpl.java:662)
at io.grpc.internal.CensusTracingModule$TracingClientInterceptor.interceptCall(CensusTracingModule.java:382)
at io.grpc.ClientInterceptors$InterceptorChannel.newCall(ClientInterceptors.java:104)
at io.grpc.internal.CensusStatsModule$StatsClientInterceptor.interceptCall(CensusStatsModule.java:675)
at io.grpc.ClientInterceptors$InterceptorChannel.newCall(ClientInterceptors.java:104)
at com.google.api.gax.grpc.GrpcHeaderInterceptor.interceptCall(GrpcHeaderInterceptor.java:81)
at io.grpc.ClientInterceptors$InterceptorChannel.newCall(ClientInterceptors.java:104)
at com.google.api.gax.grpc.GrpcMetadataHandlerInterceptor.interceptCall(GrpcMetadataHandlerInterceptor.java:55)
at io.grpc.ClientInterceptors$InterceptorChannel.newCall(ClientInterceptors.java:104)
at io.grpc.internal.ManagedChannelImpl.newCall(ManagedChannelImpl.java:636)
at com.google.api.gax.grpc.GrpcClientCalls.newCall(GrpcClientCalls.java:66)
at com.google.api.gax.grpc.GrpcDirectCallable.futureCall(GrpcDirectCallable.java:58)
at com.google.api.gax.grpc.GrpcExceptionCallable.futureCall(GrpcExceptionCallable.java:62)
at com.google.api.gax.rpc.UnaryCallable$1.futureCall(UnaryCallable.java:126)
at com.google.api.gax.rpc.UnaryCallable.futureCall(UnaryCallable.java:87)
at com.google.cloud.firestore.FirestoreImpl.sendRequest(FirestoreImpl.java:330)
at com.google.cloud.firestore.UpdateBuilder.commit(UpdateBuilder.java:608)
at com.google.cloud.firestore.WriteBatch.commit(WriteBatch.java:41)
at com.google.cloud.firestore.DocumentReference.create(DocumentReference.java:141)
at com.google.cloud.firestore.CollectionReference.add(CollectionReference.java:115)
at com.google.cloud.firestore.CollectionReference.add(CollectionReference.java:141)
at PriceDifferenceTask.findMaxProfitAndPercentPriceDifference(PriceDifferenceTask.kt:167)
at PriceDifferenceTask.access$findMaxProfitAndPercentPriceDifference(PriceDifferenceTask.kt:15)
at PriceDifferenceTask$run$1.call(PriceDifferenceTask.kt:64)
at PriceDifferenceTask$run$1.call(PriceDifferenceTask.kt:15)
at rx.functions.Functions$6.call(Functions.java:169)
at rx.internal.operators.OperatorZip$Zip.tick(OperatorZip.java:252)
at rx.internal.operators.OperatorZip$Zip$InnerSubscriber.onNext(OperatorZip.java:323)
at rx.internal.util.ScalarSynchronousObservable$WeakSingleProducer.request(ScalarSynchronousObservable.java:276)
at rx.Subscriber.setProducer(Subscriber.java:211)
at rx.internal.util.ScalarSynchronousObservable$JustOnSubscribe.call(ScalarSynchronousObservable.java:138)
at rx.internal.util.ScalarSynchronousObservable$JustOnSubscribe.call(ScalarSynchronousObservable.java:129)
at rx.Observable.unsafeSubscribe(Observable.java:10256)
at rx.internal.operators.OperatorZip$Zip.start(OperatorZip.java:202)
at rx.internal.operators.OperatorZip$ZipSubscriber.onNext(OperatorZip.java:143)
at rx.internal.operators.OperatorZip$ZipSubscriber.onNext(OperatorZip.java:109)
at rx.internal.util.ScalarSynchronousObservable$WeakSingleProducer.request(ScalarSynchronousObservable.java:276)
at rx.Subscriber.setProducer(Subscriber.java:209)
at rx.internal.util.ScalarSynchronousObservable$JustOnSubscribe.call(ScalarSynchronousObservable.java:138)
at rx.internal.util.ScalarSynchronousObservable$JustOnSubscribe.call(ScalarSynchronousObservable.java:129)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.subscribe(Observable.java:10352)
at rx.Observable.subscribe(Observable.java:10319)
at rx.Observable.subscribe(Observable.java:10159)
at PriceDifferenceTask.run(PriceDifferenceTask.kt:66)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)
Implementation
build.gradle
group 'coinverse'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.2.71'
ext.junitJupiterVersion = '5.0.3'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.3'
}
}
apply plugin: 'java'
apply plugin: 'kotlin'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
testImplementation group: 'junit', name: 'junit', version: '4.12'
// JUnit Jupiter API and TestEngine implementation
testCompile("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
testRuntime("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")
testCompile("org.assertj:assertj-core:3.10.0")
// To avoid compiler warnings about #API annotations in JUnit code
testCompileOnly('org.apiguardian:apiguardian-api:1.0.0')
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.4.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.2'
implementation 'com.google.firebase:firebase-admin:6.5.0'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
Gradle Dependency Tree
Attempted Solutions
After examining similar issues on StackOverflow this appears to be related to a conflict with Google's Guava library. From the Gradle Dependencies above some libraries were calling older versions of Guava. All libraries in the build.gradle have been updated to their latest versions.
Rebuilding project.
IntelliJ Invalidate Cache and Restart
Implementing current version of Guava in build.gradle: api "com.google.guava:guava:27.0-jre"
Implementing lowest version of Guava in build.gradle found in dependency tree: implementation 'com.google.guava:guava:19.0'
Implementing highest version of Guava in build.gradle found in dependency tree: implementation 'com.google.guava:guava:20.0'
Attempting to exclude lowest version of Guava in build.gradle found in dependency tree: configurations {all*.exclude 'com.google.guava:guava:19.0'}
add the current version 27.0:
dependencies {
api "com.google.guava:guava:27.0-jre"
}
and exclude both other versions 19.0 and 20.0, wherever they may be referenced.
./gradlew app:dependencies > dependencies.txt
or check with:
./gradlew app:dependencies | grep guava
for example (the firebase-admin is certainly a candidate):
// https://mvnrepository.com/artifact/com.google.firebase/firebase-admin
implementation ("com.google.firebase:firebase-admin:6.5.0") {
exclude group: "com.google.guava", module: "guava"
}
there may be further references present.
Solution
The Jar build started working again after updating my library dependencies and redefining the Project level SDK when re-pulling a version built on a different machine from Github.
Update to dependencies
Changed compile to implementation.
Updated version numbers by searching for each project's latest version on Google.
build.grade
buildscript {
ext.kotlin_version = '1.3.10'
ext.junitJupiterVersion = '5.3.2'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.3'
}
}
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.2.51'
}
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testImplementation group: 'junit', name: 'junit', version: '5.3.2'
// JUnit Jupiter API and TestEngine implementation
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
testRuntime("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")
testImplementation "org.assertj:assertj-core:3.11.1"
// To avoid compiler warnings about #API annotations in JUnit code
testCompileOnly 'org.apiguardian:apiguardian-api:1.0.0'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.5.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.4'
implementation 'com.google.firebase:firebase-admin:6.6.0'
implementation 'com.google.apis:google-api-services-youtube:v3-rev206-1.25.0'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}