elasticsearch-rest-high-level-client dependency is not working - elasticsearch

it's my first question.
I have to using ES rest high level client.
my ES server is 6.8.x, so i write my build.gradle file.
compile "org.elasticsearch.client:elasticsearch-rest-high-level-client:6.8.5"
but my project dependency works like below.
Gradle: org.elasticsearch.client:elasticsearch-rest-client:7.6.2
Gradle: org.elasticsearch.client:elasticsearch-rest-high-level-client:6.8.5
Gradle: org.elasticsearch.client:elasticsearch-rest-high-level-client:7.6.2
.. and more ...
why the wrong version 7.6.2 imported?

i got the answer myself.
the spring boot 2.3.x are using Elasticsearch 7.6.2 by dependency management(BOM).
https://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/#preface.versions
the answer is overriding the version in gradle.
ext['elasticsearch.version'] = '6.8.5'
be careful... this is not working.
ext {
elasticsearch.version = '6.8.5'
}
good!

Related

Spring boot gradle project with kotlin setup issue

Hello i want to create a Spring boot app with kotlin and Gradle but i have this issue in the plugins line, it doens't recognize any plugin i add ,i couldn't undrestand what's missing, i'm using Gradle 6.3v , jdk 8
Error:
Error
And that's the build.gradle file
build.gradle.kts
Your first plugin declaration has a typo in the version:
kotlin("jvm") version "1.3.11" needs to be kotlin("jvm") version "1.3.71"
I would start by changing that so all usages of kotlin plugins are aligned on a recent version.
If that does not resolve the problem, try running the build from the CLI with the added flag --stacktrace which may tell you more about why is the plugin not found.

gradle import elasticsearch 7.6.1, but imported 7.6.1 and 6.4.3 together

I create a project with spring boot project and gradle.
In build.gradle file, I import elasticsearch rest high level client like this:
compile group: 'org.elasticsearch.client', name: 'elasticsearch-rest-high-level-client', version: '7.6.1'
But after building, I found it imported elasticsearch jars both version 7.6.1 and 6.4.3.
I removed elasticsearch folders from in local gradle repository folder, and build again. But the result is the same.
I don't know why version 6.4.3 imported. I don't use any other elasticsearch related jars in my project.
Who can tell me where the 6.4.3 jars come from? How can I remove them?
It seems Spring dependency-management-plugin control the version of es, and ignored my configuration in build.gradle. How could it do this? How can I resolve the problem?
screenshot from IDEA, it shows the elastic jars in two versions imported together
I resolved it by adding these lines to build.gradle:
dependencyManagement {
dependencies {
dependency 'org.elasticsearch:elasticsearch:7.6.1'
dependency 'org.elasticsearch.client:elasticsearch-rest-client:7.6.1'
dependency 'org.elasticsearch.client:elasticsearch-rest-high-level-client:7.6.1'
}
}

How to use JPA metamodel with gradle, intellij IDEA?

I am using java 8, spring boot 2.0.0, spring-data-jpa(spring-boot-starter-data-jpa), gradle, intellij. I've been trying to use JPA Metamodel, but having difficulty on finding how to configure.
Metamodels for Entity classes aren't just generated.
I guessed it would be simple, but now it seems that can be wrong. How can I use it?
JDK11 / Gradle 5.0 / Hibernate 5.3.7.Final
sourceSets.main.java.srcDirs += "${buildDir}/generated"
compileJava {
options.annotationProcessorGeneratedSourcesDirectory = file("${buildDir}/generated")
}
dependencies {
annotationProcessor("javax.xml.bind:jaxb-api")
annotationProcessor("org.hibernate:hibernate-jpamodelgen")
}
Generated Metamodel classes will be generated at 'build/generated'
If you are using JDK8 or Hibernate 5.4+, annotationProcessor("javax.xml.bind:jaxb-api") may unnecessary.
I did this the other day using the scalified metamodel gradle plugin (https://plugins.gradle.org/plugin/com.scalified.plugins.gradle.metamodel). I'm using Spring Boot 2.0.5, but I don't see why it wouldn't work the same with Spring Boot 2.0.0. I'm using Gradle 4.8.1 as well.
Below is an excerpt of my build.gradle.
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath (
"org.springframework.boot:spring-boot-gradle-plugin:2.0.0",
"gradle.plugin.com.scalified.plugins.gradle:metamodel:0.0.1");
}
}
apply plugin: "com.scalified.plugins.gradle.metamodel"
// The plugin will default to the latest version of Hibernate if this is not specified
metamodel {
hibernateVersion = '5.2.14.Final' // For Spring Boot 2.0.0
hibernateVersion = '5.2.17.Final' // For Spring Boot 2.0.5
}
This builds the metamodal files under src/generated and they can be used in your code. I had to also change an IntelliJ setting because IntelliJ's Build Automatically excludes some Gradle tasks that could be long running. See Automatically run Gradle task in project build with IntelliJ IDEA and https://youtrack.jetbrains.com/issue/IDEA-175165 for more details.
This setting I changed to overcome this is: Preferences->Build/Execution/Deployment->Gradle->Runner->Delegate IDE build/run actions to Gradle. An alternative would be to run the metamodelCompile gradle task manually as needed. That would lessen the time to rebuild by a little if you aren't frequently change your entities.

logging.pattern.console in application.properties not working

I'm trying to change the log pattern in my Spring Boot project. I want to modify the application.properties file, and according to the documentation I can do that using the property logging.pattern.console. My application.properties file looks simply like this:
logging.pattern.console=%d
and it should show only the date in the log line, but I keep seeing the default Spring Boot log pattern. Other kind of properties, like logging.level, work fine.
What am I missing?
Thanks,
Sara
I faced similar issue. The problem is with the springboot version only. Here is how i solved it.
1. First of all i excluded default logger provided by spring-boot-starter-web In build.gradle file [Note. you can do similar thing for maven as well] . If you are not using spring-boot-starter-web then skip this step.
compile ('org.springframework.boot:spring-boot-starter-web:1.4.1.RELEASE'){ exclude group: "org.hibernate" exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' }
2 Now i excluded logback as well, since i used log4j2
configurations { provided all*.exclude group: 'ch.qos.logback' }
3 Now add dependency for log4j2:
compile('org.springframework.boot:spring-boot-starter-log4j2'){
force = true
}
4 All the above steps we to ensure that log4j2 jar is used correctly. As i said problem arose due to wrong version of springboot. Springboot 1.4x versions like
1.4.5, 1.4.7 ... doesn't support this feature, you will need to use 1.5x version.
do the following
Keep this dependency before apply plugin
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.0.RELEASE")
and then apply plugin:
apply plugin: 'org.springframework.boot'
Mostly while configuring you have 1,2,3 steps already covered. Just change the version of spring boot to 1.5.0 or above. And apply Plugin org.springframework.boot, It should work like a charm
Just change the pattern to logging.pattern.console = '%d'.
%d is not parsed just surround it with quotes.

Gradle: Compile Dependencies

I'm using mongodb with Spring Boot. Recently, my mongodb was upgraded to version 3.0.
I'm using the following Gradle dependencies for Spring:
buildscript {
ext {
springBootVersion = '1.2.6.RELEASE'
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter-data-mongodb'
}
If I look on maven repositories for Gradle: 'org.springframework.boot:spring-boot-starter-data-mongodb:1.2.6.RELEASE', I see the following (http://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-mongodb/1.2.6.RELEASE):
The dependencies for the mongo-java-drivers are 2.12.5 under the "Version" column. I was wondering what the "Update" column is there for and how can I use the version of the mongo-java-drivers listed there instead (3.0.4)?
Since I'm using mongo 3.0, I would like to use the 3.0.4 java-drivers instead of 2.12.5 as I need to update my java-drivers to be at least 2.13 before they will work with my mongodb 3.0: http://docs.mongodb.org/manual/release-notes/3.0-scram/#upgrade-drivers
Just add the following dependency to your project dependencies:
compile 'org.mongodb:mongo-java-driver:3.0.4'
This will explicitly set there mongodb Java driver to the newest version and will overrun the transitive dependency version of spring-boot-starter-data-mongodb.
BTW, the "Updates" column means the newest version for a specific Artifact.
You can force the usage of a newer version of a dependency by just explicitly adding the dependency version that you want to use in the pom.xml.
Then Maven will use the explicitly specified version to compile.
FYI, you can exclude a dependency triggered by a direct dependency by using the exclude element.
See this doc to know how maven manages dependencies.
If you are using Gradle, see this page. In fact, you exclude the MongoDB transitive dependency triggered by spring boot and you explicitly add the latest version as a direct dependency.

Resources