Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add external jar in gradle

How can I add an external library in gradle? My build.gradle contains:

buildscript {
    repositories {
        mavenCentral()
        maven {
            name = "forge"
            url = "http://files.minecraftforge.net/maven"
        }
        maven {
            name = "sonatype"
            url = "https://oss.sonatype.org/content/repositories/snapshots/"
        }
    }
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:1.1-SNAPSHOT'
    }
}

My root folder is /FORGE/. I want to add /FORGE/build/libs/spigot.jar as a dependency.

like image 304
QuadX Avatar asked Mar 29 '14 17:03

QuadX


People also ask

Where are Gradle dependency jars?

Gradle declares dependencies on JAR files inside your project's module_name /libs/ directory (because Gradle reads paths relative to the build.gradle file). This declares a dependency on version 12.3 of the "app-magic" library, inside the "com.example.android" namespace group.


1 Answers

As explained in the documentation:

dependencies {
    compile files('libs/spigot.jar')
}

The above will add the libs/spigot.jar file to the compile configuration. You can of course add it to any other configuration (runtime, etc.).

Note that using build/libs is an extremely bad idea, since the whole build directory will be deleted as soon as you execute gradle clean. The build directory is used to store artifacts generated by the build.

like image 141
JB Nizet Avatar answered Sep 20 '22 06:09

JB Nizet