Question on Compile Elasticsearch into a JAR like how it was done in the Maven repository

Greetings there

I have a Maven project where I have utilized a lot of functionalities from Elasticsearch. More specifically, it was imported in this way:

        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>5.6.10</version>
        </dependency>

Now that I am making some tweaks to Elasticsearch source code in order to get some extra functionality, and I have compiled my code using ./gradlew assemble and have import the compiled jar from ES_SOURCE_CODE_FOLDER/core/build/distributions/elasticsearch-5.6.10-SNAPSHOT.jar in Maven by specifying a systemPath and scope (for now, I know this not what people would actually do but just to test out my implementation):

        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>5.6.10</version>
            <scope>system</scope>
            <systemPath>/Users/extendedRange/elasticsearch/core/build/distributions/elasticsearch-5.6.10-SNAPSHOT.jar</systemPath>
        </dependency>

However I realize that after I do this, I was unable to compile my program anymore, as the following import was no longer working:

import org.apache.lucene.index.Fields;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.queryparser.flexible.standard.QueryParserUtil;

My question is, did I compile Elasticsearch in an incorrect way? How am I suppose to compile it in the same way as it is compiled in the Maven repository, so that I can still get my imports from org.apache.lucene working?

In case if these information are needed:
My changes to Elasticsearch code are very limited, based on a branch off 857bfc2ac43ae3986197aeb2177ab5ff87d9f3b4 which still have the 5.6.10 as version number.
My working environments are:

$ java -version
openjdk version "1.8.0_212"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_212-b03)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.212-b03, mixed mode)

$ mvn --version
[MVNVM] Using maven: 3.5.2
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T00:58:13-07:00)
Maven home: /Users/extendedRange/.mvnvm/apache-maven-3.5.2
Java version: 1.8.0_212, vendor: AdoptOpenJDK
Java home: /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.13.6", arch: "x86_64", family: "mac"

$ gradle --version

------------------------------------------------------------
Gradle 4.7
------------------------------------------------------------

Build time:   2018-04-18 09:09:12 UTC
Revision:     b9a962bf70638332300e7f810689cb2febbd4a6c

Groovy:       2.4.12
Ant:          Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM:          1.8.0_212 (AdoptOpenJDK 25.212-b03)
OS:           Mac OS X 10.13.6 x86_64

Is there a reason you aren't using the published jar that exists in maven central? By depending on that, you would get all the transitive dependencies, which is what you are missing (eg Lucene). If you must build it locally, then you will need to pull all of these dependencies yourself.

I am making some tweaks to the Elasticsearch source code to get some extra functionality.

Any suggestions on getting transitive dependencies? I know that I can remove the system scope iin pom.xml and install the jar into my local maven repository. It does get rid of the missing import error in IntellJ but I still can't compile it upon running mvn install because the lucene index are still missing.

OK I figure out the solution

Just do the following

mvn install:install-file \
   -Dfile=/Users/extendedRange/elasticsearch/core/build/distributions/elasticsearch-5.6.10-SNAPSHOT.jar \
   -DgroupId=org.elasticsearch \
   -DartifactId=elasticsearch \
   -Dversion=5.6.10-X \
   -Dpackaging=jar \
   -DpomFile=/Users/extendedRange/elasticsearch/core/build/distributions/elasticsearch-5.6.10-SNAPSHOT.pom

And then use

        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>5.6.10-X</version>
        </dependency>

Instead

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.