Migrating from G3 to G4, is anyone seeing any prob...
# questions
p
Migrating from G3 to G4, is anyone seeing any problems getting elasticsearch-plugin:3.0.2 to pull in the right org.elasticsearch:7.3.0 and org.apache.lucene:8.1.0? I'm seeing way older versions of those libraries getting built and the plugin is (obviously) falling over. Gradle dependency hell!
p
I might have encountered a similar issue in the past while migrating from Grails 3 to 4 or higher. The main problem lies in the dependencies being resolved to older versions due to conflicts or transitive dependencies introduced by other plugins or libraries in the project. Here are some steps you can take to ensure that the correct version of
org.elasticsearch:7.3.0
and
org.apache.lucene:8.1.0
are pulled in: 1. Force Specific Versions: In the
build.gradle
file, force the specific versions of Elasticsearch and Lucene to be used.
Copy code
configurations.all {
       resolutionStrategy {
           force 'org.elasticsearch:elasticsearch:7.3.0'
           force 'org.apache.lucene:lucene-core:8.1.0'
       }
   }
2. Exclude Older Versions: Ensure that any older versions of these libraries are excluded from the transitive dependencies of other plugins or libraries. You can do this by adding
exclude
clauses in your dependencies:
Copy code
dependencies {
       implementation('your.dependency') {
           exclude group: 'org.elasticsearch', module: 'elasticsearch'
           exclude group: 'org.apache.lucene', module: 'lucene-core'
       }
   }
3. Check Transitive Dependencies: Use the
dependencyInsight
task in Gradle to check for any transitive dependencies that might be pulling in older versions:
Copy code
./gradlew dependencyInsight --dependency org.elasticsearch --configuration compileClasspath
./gradlew dependencyInsight --dependency org.apache.lucene --configuration compileClasspath
This will give you detailed information on which dependencies are pulling in the versions of
org.elasticsearch
and
org.apache.lucene
. By using these steps, you should be able to pinpoint and resolve issues with older versions of Elasticsearch and Lucene being pulled into your project, ensuring that the correct versions are used with the
elasticsearch-plugin:3.0.2
during your migration from Grails 3 to Grails 4.
❤️ 1
p
Wow, fantastic, thanks! I actually read up a bit more on the 'exclude' and used that, so it now builds and runs! I actually put in specific 'compiles' for ES after I found it was still trying to use an older version of the rest client.
Copy code
compile("org.grails.plugins:elasticsearch:3.0.1") {
        exclude group:'elasticsearch', module:'elasticsearch'
        exclude group:'elasticsearch.client', module:'elasticsearch.client'
    }
    implementation 'org.elasticsearch:elasticsearch:7.3.0'
    implementation 'org.elasticsearch.client:elasticsearch-rest-client:7.3.0'
    implementation 'org.elasticsearch.client:elasticsearch-rest-high-level-client:7.3.0'
That seems to work. Although I do now have a problem with domain class marshalling of dates, complaining about the date being 'malformed at "Z"'.
It's trying to convert a
Timestamp
into a full date string but failing because there's no
toCalendar()
method on
Timestamp
. Wondering if I'm missing some other dependency issue with Groovy itself getting confused.
p
If you could quickly get a sample application replicating the problem, I will try to look into it
p
I think it might be to do with my setup here as I can't see how anyone else wouldn't have the same problem if they're indexing a
Timestamp
property. I've changed the marshalling (JSONDomainFactory line 167) in my own branch:
Copy code
//                TimeZone.setDefault(TimeZone.getTimeZone('UTC'))
//                res = res.toCalendar().getTime().format("yyyy-MM-dd'T'HH:mm:ss'Z'")
                ZonedDateTime utc = ZonedDateTime.now(ZoneOffset.UTC)
                res = utc.format(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"))
and that seems to work but I don't know if folks are using later Java versions, etc. which might break for them.
It's that
res.toCalendar()
that fails with a missing method exception.