配置 Gradle 项目

本页介绍如何将 JxBrowser 添加到 Gradle 项目中。

要将 JxBrowser 添加到 Gradle 项目中,您必须在构建脚本文件 build.gradle(.kts) 中添加 JxBrowser Gradle 插件,并在那里配置项目的依赖项

应用插件

要应用 JxBrowser Gradle 插件,请使用 Gradle DSL 中的 plugins 块:

plugins {
    id 'com.teamdev.jxbrowser' version '1.0.2'
}
plugins {
    id("com.teamdev.jxbrowser") version "1.0.2"
}

配置插件

应用了插件后,可以通过 build.gradle(.kts) 文件中的 jxbrowser 扩展来配置该插件。

版本

使用 version 属性设置所需的库版本:

jxbrowser {
    version '7.38.2'
}
jxbrowser {
    version = "7.38.2"
}

version 属性是强制性的,省略它将导致 IllegalStateException

存储库

您可以指定要使用的 JxBrowser 存储库的位置,可以是北美或欧洲:

jxbrowser {
    version '7.38.2'
    repository Repository.EUROPE
}
jxbrowser {
    version = "7.38.2"
    repository = Repository.EUROPE
}

您还可以通过其 URL 指定自定义存储库,如下所示:

jxbrowser {
    version '7.38.2'
    repository 'https://my.custom.repository'
}
jxbrowser {
    version = "7.38.2"
    repository = "https://my.custom.repository"
}

如果未指定 repository 属性,则位置将设置为北美。

预览版本

使用 includePreviewBuilds() 将包含 JxBrowser 预览版本的存储库添加到项目中。

jxbrowser {
    version '7.38.2'
    includePreviewBuilds()
}
jxbrowser {
    version = "7.38.2"
    includePreviewBuilds()
}

依赖项

跨平台

要添加适用于 Windows、macOS 和 Linux 的 JxBrowser 库,请添加以下代码:

dependencies {
    implementation jxbrowser.crossPlatform
}
dependencies {
    implementation(jxbrowser.crossPlatform)
}

特定平台

如果您只需要特定平台的 JxBrowser JAR 文件,您可以使用如下所述的适当依赖项。

如果您的 Java 应用程序仅在 Windows 和 macOS 平台上运行,并且您不需要 Linux 依赖项,则可以只包含 Windows 和 macOS 依赖项。

Windows 32 位

dependencies {
    implementation jxbrowser.win32
}
dependencies {
    implementation(jxbrowser.win32)
}

Windows 64 位

dependencies {
    implementation jxbrowser.win64
}
dependencies {
    implementation(jxbrowser.win64)
}

macOS 64 位

dependencies {
    implementation jxbrowser.mac
}
dependencies {
    implementation(jxbrowser.mac)
}

macOS 64 位 ARM

dependencies {
    implementation jxbrowser.macArm
}
dependencies {
    implementation(jxbrowser.macArm)
}

Linux 64 位

dependencies {
    implementation jxbrowser.linux64
}
dependencies {
     implementation(jxbrowser.linux64)
}

Linux 64 位 ARM

dependencies {
    implementation jxbrowser.linuxArm
}
dependencies {
    implementation(jxbrowser.linuxArm)
}

当前平台

要检测当前平台并添加相应的 Chromium 二进制文件,请使用以下依赖项:

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

GUI 工具箱

Swing

dependencies {
    implementation jxbrowser.swing
}
dependencies {
    implementation(jxbrowser.swing)
}

JavaFX

dependencies {
    implementation jxbrowser.javafx
}
dependencies {
    implementation(jxbrowser.javafx)
}

SWT

dependencies {
    implementation jxbrowser.swt
}
dependencies {
    implementation(jxbrowser.swt)
}

总结

以下是 build.gradle(.kts) 的完整代码:

import com.teamdev.jxbrowser.gradle.Repository

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

jxbrowser {
    // JxBrowser 版本。必填字段。
    version '7.38.2'

    // 要使用的 JxBrowser 存储库位置。要么是北美,要么是欧洲。
    // 如果未指定,位置将设置为北美。
    repository Repository.NORTH_AMERICA

    // 或者,它可以通过其 URL 指向自定义存储库,如下所示:
    // repository = "https://my.custom.repository"

    // 将带有 JxBrowser 预览版本的存储库添加到项目中。
    includePreviewBuilds()
}

dependencies {
    // 添加对核心 JxBrowser API 的依赖项。
    implementation jxbrowser.core

    // 为所有支持的平台添加对 Chromium 二进制文件的依赖项。
    implementation jxbrowser.crossPlatform

    // 添加对特定平台的 Chromium 二进制文件的依赖项。
    implementation jxbrowser.mac
    implementation jxbrowser.macArm
    implementation jxbrowser.win32
    implementation jxbrowser.win64
    implementation jxbrowser.linux64
    implementation jxbrowser.linuxArm

    // 检测当前平台并添加相应的 Chromium 二进制文件。
    implementation jxbrowser.currentPlatform

    // 添加对 UI 工具包集成的依赖项。
    implementation jxbrowser.swt
    implementation jxbrowser.swing
    implementation jxbrowser.javafx
}
import com.teamdev.jxbrowser.gradle.Repository

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

jxbrowser {
    // JxBrowser 版本。必填字段。
    version = "7.38.2"

    // 要使用的 JxBrowser 存储库位置。要么是北美,要么是欧洲。
    // 如果未指定,位置将设置为北美。
    repository = Repository.NORTH_AMERICA

    // 或者,它可以通过其 URL 指向自定义存储库,如下所示:
    // repository = "https://my.custom.repository"

    // 将带有 JxBrowser 预览版本的存储库添加到项目中。
    includePreviewBuilds()
}

dependencies {
    // 添加对核心 JxBrowser API 的依赖项。
    implementation(jxbrowser.core)

    // 为所有支持的平台添加对 Chromium 二进制文件的依赖项。
    implementation(jxbrowser.crossPlatform)

    // 添加对特定平台的 Chromium 二进制文件的依赖项。
    implementation(jxbrowser.mac)
    implementation(jxbrowser.macArm)
    implementation(jxbrowser.win32)
    implementation(jxbrowser.win64)
    implementation(jxbrowser.linux64)
    implementation(jxbrowser.linuxArm)
    
    // 检测当前平台并添加相应的 Chromium 二进制文件。
    implementation(jxbrowser.currentPlatform)
    
    // 添加对 UI 工具包集成的依赖项。
    implementation(jxbrowser.swt)
    implementation(jxbrowser.swing)
    implementation(jxbrowser.javafx)
}
Go Top