Add an external jar to gradle


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] ------------------------------------------------------------------------

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:

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 but it's specific to x-pack that I don't use.

If you have any ideas please feel free :slight_smile:


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

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"

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

First of all, thanks for the fix !

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

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.

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