More usefully, let’s look at what’s failing here. So, in line 2797 of the log file we see the actual exception at the heart of this: java.lang.NoSuchFieldError: LUCENE_3_1
. Looking at the exception log, we can see this happens at org.apache.lucene.analysis.util.CharacterUtils.getInstance(CharacterUtils.java:50)
, so line 50 of the relevant source code for the Lucene CharacterUtils
class.
The CharacterUtils
class itself is in turn contained in the lucene-analyzers-common
dependency. Loading the source code for the version included in OpenMRS Core, we see that this line looks like this:
@Deprecated
public static CharacterUtils getInstance(Version matchVersion) {
return matchVersion.onOrAfter(Version.LUCENE_3_1) ? JAVA_5 : JAVA_4; // <- this is line 50
}
The Version
class referenced here is org.apache.lucene.util.Version
and defined in the lucene-core
dependency. And, looking at the source code for the version included in OpenMRS, there indeed is no Version.LUCENE_3_1
field.
So how did that happen?
Well, it turns out the lucene-analyzers-common
dependency is not defined in the OpenMRS POM directly, but rather defined by the hibernate-search
dependency, which in turn depends on lucene-analyzers-common
version 4.10.4. So we’ve got dependencies from two different versions of Lucene hanging around on the classpath.
One way to handle this would be to add an entry for lucene-analyzers-common
to the OpenMRS POM. But that wouldn’t solve the issue of the HibernateSearch version depending on Lucene version 4. So what we really need to do is to upgrade HibernateSearch to a version that is compatible with Lucene 5.
Here, we can use https://mvnrepository.com to do a little sleuthing. lucene-analyzers-common
is used by 600 artifacts, among which is hibernate-search-engine
. We’re currently using version 5.3.0.Final which depends on Lucene 4.10.4. 5.4.0.Final also depends on Lucene 4.10.4, so to get to a version of HibernateSearch that is compatible with Lucene 5.x, we need to migrate to the 5.5.x series. I would think 5.5.8.Final makes the most sense. But note that this depends on Lucene 5.3.1. So try bumping the HibernateSearch version and the Lucene version to 5.5.8.Final and 5.3.1 respectively.
When you try to build that locally, there are likely to be some issues related to the OpenMRS code that uses HibernateSearch and Lucene. See if you can get anywhere with those.