For the complete documentation index, see llms.txt. This page is also available as Markdown.

Build Tools (Gradle, SBT)

Configuring Deeplearning4j with Gradle, SBT, and other build tools

Overview

While Maven is the primary build tool used and tested by the DL4J team, the library works with other JVM build systems. This page documents setup for Gradle (Groovy and Kotlin DSL), SBT, Leiningen (Clojure), and Ivy.

The core dependency pattern is the same across all tools: you need deeplearning4j-core and exactly one ND4J backend (nd4j-native-platform for CPU or nd4j-cuda-12.9-platform for GPU).

Gradle

Groovy DSL (build.gradle)

plugins {
    id 'java'
}

repositories {
    mavenCentral()
}

ext {
    dl4jVersion = '1.0.0-rewrite'
}

dependencies {
    // Core DL4J
    implementation "org.deeplearning4j:deeplearning4j-core:${dl4jVersion}"

    // CPU backend (replace with nd4j-cuda-12.9-platform for GPU)
    implementation "org.nd4j:nd4j-native-platform:${dl4jVersion}"

    // Logging
    implementation 'ch.qos.logback:logback-classic:1.2.11'
}

Kotlin DSL (build.gradle.kts)

GPU with Gradle

Replace the CPU backend:

Additional Modules with Gradle

Dependency Resolution in Gradle

Gradle's dependency resolution differs from Maven's. If you encounter version conflicts:

To exclude a transitive dependency:

Gradle and Snapshot Builds

Gradle has a known issue with snapshot artifacts that use Maven classifiers (the -platform artifacts). If you need snapshots, add the Sonatype snapshots repository and prefer non-platform classifiers with an explicit OS classifier:

See the Snapshots page for the full workaround. For production use, Maven is recommended for snapshot dependencies due to a Gradle bug with classifier-based snapshot resolution.

SBT

build.sbt

SBT with GPU

SBT Resolvers for Snapshots

SBT Assembly (fat JAR)

Add the sbt-assembly plugin to project/plugins.sbt:

Then in build.sbt:

Run with sbt assembly to produce a fat JAR.

Note: SBT, like Gradle, requires explicit openblas dependencies when using nd4j-native without the -platform wrapper. The -platform artifact handles this automatically. See the nd4j-native-platform pom to check the required openblas version if you manage dependencies manually.

Leiningen (Clojure)

Leiningen uses a Clojure-based build file. Add DL4J via the :dependencies vector in project.clj:

Leiningen with GPU

Leiningen Snapshots

Note: After downloading via Leiningen, you may need to double-click the downloaded JAR files to register them in your local Maven repository if you are working with Eclipse or another IDE.

Ivy

For Ant-based builds using Ivy, add the following to your ivy.xml:

Add the Maven Central resolver to ivysettings.xml:

Dependency Resolution Tips

Verify which backend is loaded

Regardless of build tool, add this to your main method to confirm the correct ND4J backend is active:

Common build issues

Issue: UnsatisfiedLinkError or missing native library at runtime. Cause: The platform classifier was not resolved, or openblas is missing. Fix: Use the -platform artifact, or manually add the openblas dependency matching the version in the nd4j-native-platform pom.

Issue: Multiple backends on classpath (both nd4j-native and nd4j-cuda present). Cause: Transitive dependency pulled in an unwanted backend. Fix: Exclude the unwanted backend explicitly in your build file.

Issue: Wrong Java version. Cause: DL4J 1.0.0-rewrite requires Java 11+. Fix: Set sourceCompatibility = JavaVersion.VERSION_11 in Gradle or <maven.compiler.source>11</maven.compiler.source> in Maven.

Last updated

Was this helpful?