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

**URL:** https://discuss.elastic.co/t/question-on-compile-elasticsearch-into-a-jar-like-how-it-was-done-in-the-maven-repository/196439
**Category:** Elasticsearch
**Created:** [August 23, 2019, 4:43am UTC](https://discuss.elastic.co/t/question-on-compile-elasticsearch-into-a-jar-like-how-it-was-done-in-the-maven-repository/196439 "2019-08-23T04:43:25Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Extended\_Range](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/extended_range/32/52869_2.png) [@Extended\_Range](https://discuss.elastic.co/u/Extended_Range)
#### Post date: [August 23, 2019, 4:43am UTC](https://discuss.elastic.co/t/question-on-compile-elasticsearch-into-a-jar-like-how-it-was-done-in-the-maven-repository/196439/1 "2019-08-23T04:43:25Z")

</div>

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:

```auto
        <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):

```auto
        <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:

```auto
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
```

---

<div class="post-metadata">

### Author: ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)
#### Post date: [August 30, 2019, 4:43pm UTC](https://discuss.elastic.co/t/question-on-compile-elasticsearch-into-a-jar-like-how-it-was-done-in-the-maven-repository/196439/2 "2019-08-30T16:43:46Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Extended\_Range](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/extended_range/32/52869_2.png) [@Extended\_Range](https://discuss.elastic.co/u/Extended_Range)
#### Post date: [August 30, 2019, 5:02pm UTC](https://discuss.elastic.co/t/question-on-compile-elasticsearch-into-a-jar-like-how-it-was-done-in-the-maven-repository/196439/3 "2019-08-30T17:02:00Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Extended\_Range](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/extended_range/32/52869_2.png) [@Extended\_Range](https://discuss.elastic.co/u/Extended_Range)
#### Post date: [September 4, 2019, 1:04am UTC](https://discuss.elastic.co/t/question-on-compile-elasticsearch-into-a-jar-like-how-it-was-done-in-the-maven-repository/196439/4 "2019-09-04T01:04:23Z")

</div>

OK I figure out the solution

Just do the following

```auto
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

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

```

Instead

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [October 2, 2019, 1:04am UTC](https://discuss.elastic.co/t/question-on-compile-elasticsearch-into-a-jar-like-how-it-was-done-in-the-maven-repository/196439/5 "2019-10-02T01:04:29Z")

</div>

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