List icon Contents

Adding JxBrowser to your Gradle project

The easiest way to add JxBrowser to a Gradle project is using the JxBrowser Gradle plugin. This guide describes how to use it.

Applying the plugin

You can apply the JxBrowser Gradle plugin to your Gradle project by adding it to the plugins block or as a buildscript dependency. In both cases, you need to specify the plugin version. This guide uses the latest version of the plugin, which you can find in the JxBrowser Gradle plugin releases.

Using the plugins block

In the plugins block from the Gradle DSL, please add the following code:

Kotlin
Groovy
plugins {
    id("com.teamdev.jxbrowser") version "1.2.1"
}
plugins {
    id 'com.teamdev.jxbrowser' version '1.2.1'
}

As a buildscript dependency

If you are forced to use the legacy method of applying plugins, then you can add the JxBrowser Gradle plugin as a buildscript dependency:

Kotlin
Groovy
buildscript {
  repositories {
    maven {
      url = uri("https://plugins.gradle.org/m2/")
    }
  }
  dependencies {
    classpath("com.teamdev.jxbrowser:jxbrowser-gradle-plugin:1.2.1)
  }
}

apply(plugin = "com.teamdev.jxbrowser")
buildscript {
  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
  }
  dependencies {
    classpath "com.teamdev.jxbrowser:jxbrowser-gradle-plugin:1.2.1"
  }
}

apply plugin: "com.teamdev.jxbrowser"

Configuring the plugin

Once applied, the plugin can be configured via the jxbrowser extension in the build.gradle(.kts) file.

JxBrowser version

The version property is a required property that determines the version of JxBrowser. Here’s how you can configure the plugin to use the latest version of JxBrowser:

Kotlin
Groovy
jxbrowser {
    version = "8.2.1"
}
jxbrowser {
    version '8.2.1'
}

The list of all available JxBrowser versions you can find on the Release Notes page.

Repository

JxBrowser artifacts are hosted in our own Maven repositories. We use our own repositories instead of Maven Central to speed up new version releases and ensure full control over the repository and its configuration.

The JxBrowser repositories are located in North America and Europe. You can specify which JxBrowser repository should be used by setting the repository property. The location of the JxBrowser repository affects the artifacts download speed, so you should choose the location you are geographically closer to. If the property is not specified, the repository in North America will be used.

The following code snippet shows how to use the repository located in Europe:

Kotlin
Groovy
jxbrowser {
    // The location of JxBrowser repository to use.
    // If not specified, the location is set to North America.
    repository = Repository.EUROPE
    // repository = Repository.NORTH_AMERICA
}
jxbrowser {
    // The location of JxBrowser repository to use.
    // If not specified, the location is set to North America.
    repository Repository.EUROPE
    // repository Repository.NORTH_AMERICA
}

If you prefer to store JxBrowser artifacts in a custom Maven repository, then you can configure the plugin to use it as shown below:

Kotlin
Groovy
jxbrowser {
    repository = "https://my.custom.repository"
}
jxbrowser {
    repository 'https://my.custom.repository'
}

Dependencies

JxBrowser is a cross-platform library that supports different operating systems, CPU architectures, and Java UI toolkits. It integrates with Chromium and deploys its binaries inside the JAR files. For each family of operating systems and CPU architecture, there is a separate JxBrowser dependency with the required Chromium binaries.

The size of a dependency with the Chromium binaries may vary depending on the operating system and CPU architecture. It can be up to 110MB. So, it’s important to add only the required dependencies to your project.

Platform-specific

If you develop for a specific operating system and CPU architecture, then you can add one or more platform-specific dependencies to your project using the following code:

Kotlin
Groovy
dependencies {
    implementation(jxbrowser.win32)     // Windows 32-bit
    implementation(jxbrowser.win64)     // Windows 64-bit
    implementation(jxbrowser.winArm)    // Windows 64-bit ARM
    implementation(jxbrowser.mac)       // Mac Intel
    implementation(jxbrowser.macArm)    // Mac Apple silicon
    implementation(jxbrowser.linux64)   // Linux 64-bit
    implementation(jxbrowser.linuxArm)  // Linux 64-bit ARM
}
dependencies {
    implementation jxbrowser.win32      // Windows 32-bit
    implementation jxbrowser.win64      // Windows 64-bit
    implementation jxbrowser.winArm     // Windows 64-bit ARM
    implementation jxbrowser.mac        // Mac Intel
    implementation jxbrowser.macArm     // Mac Apple silicon
    implementation jxbrowser.linux64    // Linux 64-bit
    implementation jxbrowser.linuxArm   // Linux 64-bit ARM
}

The list of supported operating systems and CPU architectures you can find in system requirements.

Current platform

If you develop for multiple platforms and want to detect the current platform and download only the corresponding Chromium binaries, then you can use the currentPlatform dependency:

Kotlin
Groovy
dependencies {
    implementation(jxbrowser.currentPlatform)
}
dependencies {
    implementation jxbrowser.currentPlatform
}

This dependency is ideal for development. If you are going to use the Gradle script for deployment, you should add all the required platform-specific dependencies. Otherwise, the binaries will be fetched only for the operating system where the Gradle script is executed.

GUI toolkit

If you use Swing, JavaFX, SWT, or Compose Desktop UI-toolkit to build GUI of your app, then please add the corresponding JxBrowser dependencies as well:

Kotlin
Groovy
dependencies {
    implementation(jxbrowser.swt)
    implementation(jxbrowser.swing)
    implementation(jxbrowser.javafx)
    implementation(jxbrowser.compose)
}
dependencies {
    implementation jxbrowser.swt
    implementation jxbrowser.swing
    implementation jxbrowser.javafx
    implementation jxbrowser.compose
}

Kotlin DSL

If you develop using Kotlin, then we recommend that you add JxBrowser Kotlin DSL for the best experience.

Kotlin
Groovy
dependencies {
    implementation(jxbrowser.kotlin)
}
dependencies {
    implementation jxbrowser.kotlin
}

Summary

Here is the complete code of build.gradle(.kts):

Kotlin
Groovy
import com.teamdev.jxbrowser.gradle.Repository

plugins {
    java
    id("com.teamdev.jxbrowser") version "1.2.1"
}

jxbrowser {
    // The JxBrowser version (required).
    version = "8.2.1"

    // The location of JxBrowser repository to use (optional).
    // It's either North America or Europe.
    // If not specified, the location is set to North America.
    repository = Repository.EUROPE
    // repository = Repository.NORTH_AMERICA

    // Alternatively, it may point to a custom repo via its URL, as follows:
    // repository = "https://my.custom.repository"
}

dependencies {
    // Adds a dependency to the platform-specific Chromium binaries.
    implementation(jxbrowser.mac)      // Mac Intel
    implementation(jxbrowser.macArm)   // Mac Apple silicon
    implementation(jxbrowser.win32)    // Windows 32-bit
    implementation(jxbrowser.win64)    // Windows 64-bit
    implementation(jxbrowser.winArm)   // Windows 64-bit ARM
    implementation(jxbrowser.linux64)  // Linux 64-bit
    implementation(jxbrowser.linuxArm) // Linux 64-bit ARM
    
    // Detects the current platform and adds the corresponding Chromium binaries.
    implementation(jxbrowser.currentPlatform)
    
    // Adds dependencies to the UI toolkit integrations.
    implementation(jxbrowser.swt)
    implementation(jxbrowser.swing)
    implementation(jxbrowser.javafx)
    implementation(jxbrowser.compose)

    // Adds dependency to the JxBrowser Kotlin DSL.
    implementation(jxbrowser.kotlin)
}
import com.teamdev.jxbrowser.gradle.Repository

plugins {
    id 'java'
    id 'com.teamdev.jxbrowser' version '1.2.1'
}

jxbrowser {
    // The JxBrowser version (required).
    version '8.2.1'

    // The location of JxBrowser repository to use (optional).
    // It's either North America or Europe.
    // If not specified, the location is set to North America.
    repository Repository.EUROPE
    // repository Repository.NORTH_AMERICA

    // Alternatively, it may point to a custom repo via its URL, as follows:
    // repository "https://my.custom.repository"
}

dependencies {
    // Adds a dependency to the platform-specific Chromium binaries.
    implementation jxbrowser.mac      // Mac Intel
    implementation jxbrowser.macArm   // Mac Apple silicon
    implementation jxbrowser.win32    // Windows 32-bit
    implementation jxbrowser.win64    // Windows 64-bit
    implementation jxbrowser.winArm   // Windows 64-bit ARM
    implementation jxbrowser.linux64  // Linux 64-bit
    implementation jxbrowser.linuxArm // Linux 64-bit ARM

    // Detects the current platform and adds the corresponding Chromium binaries.
    implementation jxbrowser.currentPlatform

    // Adds dependencies to the UI toolkit integrations.
    implementation jxbrowser.swt
    implementation jxbrowser.swing
    implementation jxbrowser.javafx
    implementation jxbrowser.compose

    // Adds dependency to the JxBrowser Kotlin DSL.
    implementation jxbrowser.kotlin
}