home.


Tagged: gradle-dependencies


Gradle: Copy all dependencies into local directory

Create a gradle build file, call it deps.gradle, as follows:

apply plugin: 'java'

repositories {
   mavenCentral()
}

dependencies {
   compile group: 'org.glassfish.jersey.bundles', name: 'jaxrs-ri', version: '2.23.1'
}

task copyDependencies(type: Copy) {
   from configurations.compile
   into 'dependencies'
}

Then call gradle -b deps.gradle copyDependencies and it’ll put all the dependencies into the dependencies/ directory.

gradle gradle-dependencies

Gradle: Project dependencies like in Eclipse

One project may depend on another, which may be on the same folder level, i.e. not a in a subdirectory.

This is easily achieved in Eclipse. And also in Gradle. You need Gradle’s ‘flat includes’.

In your project, create a settings.gradle file, with a ‘includeFlat’ directive inside to incldue a project called ‘AProject’.

    includeFlat 'AProject'

In your build.gradle specify this as needed during compile in the dependencies section (or set as needed during test etc if needs be).

    dependencies {
       compile project(':AProject')
    }

Now when you build you will pull in that project. Obviously AProject needs to be a Gradle project.

Note that this will only pull in the compile files in AProject - nothing under the /test directory.

gradle gradle-dependencies

Gradle: Dependencies

You can specify both the repositories - maven central here - and the dependencies easily enough:

            apply plugin: 'java'    

            repositories {
                    mavenCentral()
            }

            dependencies {
                    compile 'com.github.spullara.mustache.java:compiler:0.8.10'
                    compile 'org.pegdown:pegdown:1.2.1'
                    compile 'org.eclipse.jgit:org.eclipse.jgit:2.2.0.201212191850-r'
                    compile 'org.reflections:reflections:0.9.8'
            }

You need the java plugin lest it won’t understand the compile line.

If you want to specify if something is transitive or not, you’ll have to use the more verbose syntax:

            compile group: 'com.github.spullara.mustache.java', name: 'compiler', version: 0.8.10, transitive: false

These are then put into .gradle in your home directory. They’re not that easy to find or reference. You can copy all the references to a directory like so:

            task copyToLib(type: Copy) {
                from configurations.compile
                into "libs/"
            }

This would be useful in Android development where Android demands the libs be in there.

You can make eclipse’s .classpath reference the libs by first putting this at the top of your build script:

            apply plugin: 'eclipse'

And then by running ‘gradle eclipse’ on the command line.

gradle gradle-dependencies

Page 1 of 1