Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (3.4k points)

So I have tried to add my local .jar file dependency to my build.gradle file:

apply plugin: 'java'

sourceSets {

    main {

        java {

            srcDir 'src/model'

        }

    }

}

dependencies {

    runtime files('libs/mnist-tools.jar', 'libs/gson-2.2.4.jar')

    runtime fileTree(dir: 'libs', include: '*.jar')

And you can see that I added the .jar files into the referencedLibraries folder here: 

https://github.com/WalnutiQ/wAlnut/tree/version-2.3.1/referencedLibraries

But the problem is that when I run the command: gradle build on the command line I get the following error:

error: package com.google.gson does not exist

import com.google.gson.Gson;

Here is my entire repo:

 https://github.com/WalnutiQ/wAlnut/tree/version-2.3.1

1 Answer

0 votes
by (46k points)

There's a standard .jar in an original maven repository, try this:

repositories {

   mavenCentral()

}

dependencies {

   compile 'com.google.code.gson:gson:2.2.4'

}

But, If you really want to take that .jar from a local directory,

Add the following syntax next to your module Gradle (Not the app Gradle file):

repositories {

   flatDir {

       dirs 'libs'

   }

}

dependencies {

   compile name: 'gson-2.2.4'

}

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...