Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ This library is available on maven central. The latest version is always shown i

The minimum java version supported by JDA is **Java SE 8**. JDA also uses JSR 305 to support solid interoperability with Kotlin out of the box.

> [!NOTE]
> If you wish to support sending raw audio (and not Opus directly),
> you will also have to add the [`JDA-opus-jna`](opus-jna) dependency.

### Gradle

```gradle
Expand All @@ -63,12 +67,10 @@ repositories {

dependencies {
implementation("net.dv8tion:JDA:$version") { // replace $version with the latest version
// Optionally disable audio natives to reduce jar size by excluding `opus-java` and `tink`
// Optionally disable audio natives to reduce jar size by excluding `tink`
// Gradle DSL:
// exclude module: 'opus-java' // required for encoding audio into opus, not needed if audio is already provided in opus encoding
// exclude module: 'tink' // required for encrypting and decrypting audio
// Kotlin DSL:
// exclude(module="opus-java") // required for encoding audio into opus, not needed if audio is already provided in opus encoding
// exclude(module="tink") // required for encrypting and decrypting audio
}
}
Expand All @@ -81,13 +83,8 @@ dependencies {
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>$version</version> <!-- replace $version with the latest version -->
<!-- Optionally disable audio natives to reduce jar size by excluding `opus-java` and `tink` -->
<!-- Optionally disable audio natives to reduce jar size by excluding `tink` -->
<exclusions>
<!-- required for encoding audio into opus, not needed if audio is already provided in opus encoding
<exclusion>
<groupId>club.minnced</groupId>
<artifactId>opus-java</artifactId>
</exclusion> -->
<!-- required for encrypting and decrypting audio
<exclusion>
<groupId>com.google.crypto.tink</groupId>
Expand Down
151 changes: 16 additions & 135 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,16 @@ import de.undercouch.gradle.tasks.download.Download
import net.dv8tion.jda.tasks.*
import nl.littlerobots.vcu.plugin.resolver.VersionSelectors
import org.apache.tools.ant.filters.ReplaceTokens
import org.jreleaser.gradle.plugin.tasks.AbstractJReleaserTask
import org.jreleaser.model.Active

plugins {
environment
artifacts
`java-library`
`maven-publish`
`jda-publish`

alias(libs.plugins.shadow)
alias(libs.plugins.versions)
alias(libs.plugins.version.catalog.update)
alias(libs.plugins.jreleaser)
alias(libs.plugins.download)
}

Expand All @@ -48,7 +45,6 @@ projectEnvironment {
}

artifactFilters {
opusExclusions.addAll("natives/**", "com/sun/jna/**", "club/minnced/opus/util/*", "tomp2p/opuswrapper/*")
additionalAudioExclusions.addAll("com/google/crypto/tink/**", "com/google/gson/**", "com/google/protobuf/**", "google/protobuf/**")
}

Expand Down Expand Up @@ -129,17 +125,9 @@ dependencies {
api(libs.websocket.client)
api(libs.okhttp)

//Opus library support
api(libs.opus)

//Collections Utility
api(libs.commons.collections)

//we use this only together with opus-java
// if that dependency is excluded it also doesn't need jna anymore
// since jna is a transitive runtime dependency of opus-java we don't include it explicitly as dependency
compileOnly(libs.jna)

/* Internal dependencies */

//General Utility
Expand All @@ -154,6 +142,8 @@ dependencies {
addAll(configurations["api"].allDependencies)
addAll(configurations["implementation"].allDependencies)
addAll(configurations["compileOnly"].allDependencies)

add(project(":opus-jna"))
}

testImplementation(libs.bundles.junit)
Expand Down Expand Up @@ -253,16 +243,6 @@ val generateJavaSources by tasks.registering(SourceTask::class) {
dependsOn(sourcesForRelease)
}

val noOpusJar by tasks.registering(ShadowJar::class) {
dependsOn(shadowJar)
archiveClassifier.set(shadowJar.archiveClassifier.get() + "-no-opus")

configurations = shadowJar.configurations
from(sourceSets["main"].output)
applyOpusExclusions(artifactFilters)
manifest.from(jar.manifest)
}

val minimalJar by tasks.registering(ShadowJar::class) {
dependsOn(shadowJar)
minimize()
Expand All @@ -284,30 +264,11 @@ val sourcesJar by tasks.registering(Jar::class) {
dependsOn(sourcesForRelease)
}

val javadoc by tasks.getting(Javadoc::class) {
isFailOnError = projectEnvironment.isGithubAction

(options as? StandardJavadocDocletOptions)?.apply {
memberLevel = JavadocMemberLevel.PUBLIC
encoding = "UTF-8"

author()
tags("incubating:a:Incubating:")
links("https://docs.oracle.com/en/java/javase/$currentJavaVersion/docs/api/", "https://takahikokawasaki.github.io/nv-websocket-client/")

addStringOption("-release", "8")
addBooleanOption("Xdoclint:all,-missing", true)

overview = "$projectDir/overview.html"
}

dependsOn(generateJavaSources)
source = generateJavaSources.get().source

exclude {
it.file.absolutePath.contains("internal", ignoreCase=false)
}
}
val javadoc by configureJavadoc(
targetVersion = JavaVersion.VERSION_1_8,
failOnError = projectEnvironment.isGithubAction,
overviewFile = "$projectDir/overview.html",
)

val javadocJar by tasks.registering(Jar::class) {
dependsOn(javadoc)
Expand Down Expand Up @@ -340,7 +301,6 @@ tasks.build.configure {
dependsOn(javadocJar)
dependsOn(sourcesJar)
dependsOn(shadowJar)
dependsOn(noOpusJar)
dependsOn(minimalJar)

jar.mustRunAfter(tasks.clean)
Expand Down Expand Up @@ -426,96 +386,17 @@ compileJava.finalizedBy(verifyBytecodeVersion)
// //
////////////////////////////////////


// Generate pom file for maven central

fun MavenPom.populate() {
packaging = "jar"
name.set(project.name)
description.set("Java wrapper for the popular chat & VOIP service: Discord https://discord.com")
url.set("https://github.com/discord-jda/JDA")
scm {
url.set("https://github.com/discord-jda/JDA")
connection.set("scm:git:git://github.com/discord-jda/JDA")
developerConnection.set("scm:git:ssh:git@github.com:discord-jda/JDA")
}
licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
}
}
developers {
developer {
id.set("Minn")
name.set("Florian Spieß")
email.set("business@minn.dev")
}
developer {
id.set("DV8FromTheWorld")
name.set("Austin Keener")
email.set("keeneraustin@yahoo.com")
}
}
}

shadow {
addShadowVariantIntoJavaComponent = false
}

val stagingDirectory = layout.buildDirectory.dir("staging-deploy").get()

publishing {
publications {
register<MavenPublication>("Release") {
from(components["java"])

artifactId = project.name
groupId = project.group as String
version = project.version as String

artifact(sourcesJar)
artifact(javadocJar)

pom.populate()
}
}

repositories.maven {
url = stagingDirectory.asFile.toURI()
}
}

jreleaser {
project {
versionPattern = "CUSTOM"
}

release {
github {
enabled = false
}
}

signing {
active = Active.RELEASE
armored = true
}

deploy {
maven {
mavenCentral {
register("sonatype") {
active = Active.RELEASE
url = "https://central.sonatype.com/api/v1/publisher"
stagingRepository(stagingDirectory.asFile.relativeTo(projectDir).path)
}
}
}
}
}
registerPublication(
name = project.name,
description = "Java wrapper for the popular chat & VOIP service: Discord https://discord.com",
url = "https://github.com/discord-jda/JDA",
) {
from(components["java"])

tasks.withType<AbstractJReleaserTask>().configureEach {
mustRunAfter(tasks.named("publish"))
artifact(sourcesJar)
artifact(javadocJar)
}
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ repositories {

dependencies {
implementation(gradleApi())
implementation(libs.jreleaser)
}

kotlin {
Expand Down
25 changes: 25 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

rootProject.name = "buildSrc"

dependencyResolutionManagement {
versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
66 changes: 66 additions & 0 deletions buildSrc/src/main/kotlin/jda-publish.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.jreleaser.gradle.plugin.tasks.AbstractJReleaserTask
import org.jreleaser.model.Active

plugins {
`maven-publish`

id("org.jreleaser")
}

val stagingDirectory = layout.buildDirectory.dir("staging-deploy").get()

publishing {
repositories.maven(url = stagingDirectory.asFile.toURI())
}

jreleaser {
// Can be a subproject
gitRootSearch = true

project {
versionPattern = "CUSTOM"
}

release {
github {
enabled = false
}
}

signing {
active = Active.RELEASE
armored = true
}

deploy {
maven {
mavenCentral {
register("sonatype") {
active = Active.RELEASE
url = "https://central.sonatype.com/api/v1/publisher"
stagingRepository(stagingDirectory.asFile.absolutePath)
}
}
}
}
}

tasks.withType<AbstractJReleaserTask>().configureEach {
mustRunAfter(tasks.named("publish"))
}
11 changes: 1 addition & 10 deletions buildSrc/src/main/kotlin/net/dv8tion/jda/tasks/exclusions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,11 @@ import org.gradle.api.provider.SetProperty
import org.gradle.api.tasks.AbstractCopyTask

interface ArtifactFilters {
val opusExclusions: SetProperty<String>
val additionalAudioExclusions: SetProperty<String>
}

fun AbstractCopyTask.applyOpusExclusions(filters: ArtifactFilters) {
for (exclusion in filters.opusExclusions.get()) {
exclude(exclusion)
}
}

fun AbstractCopyTask.applyAudioExclusions(filters: ArtifactFilters) {
applyOpusExclusions(filters)

for (exclusion in filters.opusExclusions.get()) {
for (exclusion in filters.additionalAudioExclusions.get()) {
exclude(exclusion)
}
}
Loading