# Add an external jar to gradle

**URL:** <https://discuss.elastic.co/t/add-an-external-jar-to-gradle/114112>\
**Category:** Elasticsearch\
**Created:** [January 4, 2018, 2:38pm UTC](https://discuss.elastic.co/t/add-an-external-jar-to-gradle/114112 "2018-01-04T14:38:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![uderline](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/uderline/32/26245_2.png) [@uderline](https://discuss.elastic.co/u/uderline)\
**Post date:** [January 4, 2018, 2:38pm UTC](https://discuss.elastic.co/t/add-an-external-jar-to-gradle/114112/1 "2018-01-04T14:38:56Z")

</div>

Hello,

I'm developing a plugin and I would like to add an external jar dependency to my project.  
The gradle documentation says to do it this way:

```
dependencies {
    compile files("./libs/foo.jar")
}

```

When I added my jar, I got this error:

```
The closure 'org.elasticsearch.gradle.BuildPlugin$_configureConfigurations_closure5@2b92b146' is not valid as an action for argument
'org.gradle.api.internal.artifacts.dependencies.DefaultSelfResolvingDependency_Decorated@433edba9'. It should accept no parameters, or one compatible with type 
'org.gradle.api.internal.artifacts.dependencies.DefaultSelfResolvingDependency_Decorated'. It accepts (org.gradle.api.artifacts.ModuleDependency).

```

I tried to add it to my local repository.

```
$ mvn install:install-file -Dfile=duke-core-1.3-SNAPSHOT.jar -DgroupId=no.priv.garshol.duke -DartifactId=duke-core -Dversion=1.3 -Dpackaging=jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

```

Then added to my gradle:

```
compile "no.priv.garshol.duke:duke-core:1.3"

```

And I made sure to add `mavenLocal()` to the repositories and the build prompts:

```
FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all dependencies for configuration ':compileClasspath'.
> Could not find no.priv.garshol.duke:duke-core:1.3.
  Searched in the following locations:
  https://repo1.maven.org/maven2/no/priv/garshol/duke/duke-core/1.3/duke-core-1.3.pom
  https://repo1.maven.org/maven2/no/priv/garshol/duke/duke-core/1.3/duke-core-1.3.jar

```

It looks like it's ignoring my local repository but it's in my .m2 folder though.  
I sort of did what was explained in this [thread](https://discuss.elastic.co/t/class-not-found-for-a-local-jar-i-try-to-add-to-a-plugin/104369) but it's specific to x-pack that I don't use.

If you have any ideas please feel free 🙂

Regards,

---

<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:** [January 5, 2018, 7:19am UTC](https://discuss.elastic.co/t/add-an-external-jar-to-gradle/114112/2 "2018-01-05T07:19:19Z")

</div>

Regarding the jar dep failure, I think this is a bug in our `elasticsearch.esplugin` gradle plugin. I've created a PR to fix:

> <https://github.com/elastic/elasticsearch/pull/28096>

As for maven local, it looks like you install a snapshot version into your m2, but you specify a non snapshot version. Try changing your compile line to:

```auto
compile "no.priv.garshol.duke:duke-core:1.3-SNAPSHOT"

```

---

<div class="post-metadata">

**Author:** ![uderline](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/uderline/32/26245_2.png) [@uderline](https://discuss.elastic.co/u/uderline)\
**Post date:** [January 22, 2018, 10:29am UTC](https://discuss.elastic.co/t/add-an-external-jar-to-gradle/114112/3 "2018-01-22T10:29:37Z")

</div>

Hello,  
Sorry for not answering earlier but I'm a half time student.

First of all, thanks for the fix !

> [@rjernst](#):
>
> As for maven local, it looks like you install a snapshot version into your m2, but you specify a non snapshot version. Try changing your compile line to:
> 
> compile "no.priv.garshol.duke:duke-core:1.3-SNAPSHOT"

Un set my version to `-Dversion=1.3` during my man install, should I still add it to my compile line ?

---

<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:** [January 22, 2018, 4:52pm UTC](https://discuss.elastic.co/t/add-an-external-jar-to-gradle/114112/4 "2018-01-22T16:52:04Z")

</div>

I don't understand what you are asking. If you set the version to 1.3 for that dependency (either via command line or in your build.gradle file), it will look for a release version, not a snapshot.

---

<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:** [February 19, 2018, 4:52pm UTC](https://discuss.elastic.co/t/add-an-external-jar-to-gradle/114112/5 "2018-02-19T16:52:19Z")

</div>

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