Skip to content

Commit ae7933e

Browse files
committed
Move Opus support to a separate module
1 parent c2cc531 commit ae7933e

File tree

16 files changed

+201
-47
lines changed

16 files changed

+201
-47
lines changed

README.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ This library is available on maven central. The latest version is always shown i
5454

5555
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.
5656

57+
> [!NOTE]
58+
> If you wish to support sending raw audio (and not Opus directly),
59+
> you will also have to add the [`JDA-opus-jna`](opus-jna) dependency.
60+
5761
### Gradle
5862

5963
```gradle
@@ -63,12 +67,10 @@ repositories {
6367
6468
dependencies {
6569
implementation("net.dv8tion:JDA:$version") { // replace $version with the latest version
66-
// Optionally disable audio natives to reduce jar size by excluding `opus-java` and `tink`
70+
// Optionally disable audio natives to reduce jar size by excluding `tink`
6771
// Gradle DSL:
68-
// exclude module: 'opus-java' // required for encoding audio into opus, not needed if audio is already provided in opus encoding
6972
// exclude module: 'tink' // required for encrypting and decrypting audio
7073
// Kotlin DSL:
71-
// exclude(module="opus-java") // required for encoding audio into opus, not needed if audio is already provided in opus encoding
7274
// exclude(module="tink") // required for encrypting and decrypting audio
7375
}
7476
}
@@ -81,13 +83,8 @@ dependencies {
8183
<groupId>net.dv8tion</groupId>
8284
<artifactId>JDA</artifactId>
8385
<version>$version</version> <!-- replace $version with the latest version -->
84-
<!-- Optionally disable audio natives to reduce jar size by excluding `opus-java` and `tink` -->
86+
<!-- Optionally disable audio natives to reduce jar size by excluding `tink` -->
8587
<exclusions>
86-
<!-- required for encoding audio into opus, not needed if audio is already provided in opus encoding
87-
<exclusion>
88-
<groupId>club.minnced</groupId>
89-
<artifactId>opus-java</artifactId>
90-
</exclusion> -->
9188
<!-- required for encrypting and decrypting audio
9289
<exclusion>
9390
<groupId>com.google.crypto.tink</groupId>

build.gradle.kts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
1919
import de.undercouch.gradle.tasks.download.Download
2020
import net.dv8tion.jda.tasks.Version
2121
import net.dv8tion.jda.tasks.applyAudioExclusions
22-
import net.dv8tion.jda.tasks.applyOpusExclusions
2322
import net.dv8tion.jda.tasks.nullableReplacement
2423
import nl.littlerobots.vcu.plugin.resolver.VersionSelectors
2524
import org.apache.tools.ant.filters.ReplaceTokens
@@ -51,7 +50,6 @@ projectEnvironment {
5150
}
5251

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

@@ -110,17 +108,9 @@ dependencies {
110108
api(libs.websocket.client)
111109
api(libs.okhttp)
112110

113-
//Opus library support
114-
api(libs.opus)
115-
116111
//Collections Utility
117112
api(libs.commons.collections)
118113

119-
//we use this only together with opus-java
120-
// if that dependency is excluded it also doesn't need jna anymore
121-
// since jna is a transitive runtime dependency of opus-java we don't include it explicitly as dependency
122-
compileOnly(libs.jna)
123-
124114
/* Internal dependencies */
125115

126116
//General Utility
@@ -135,6 +125,8 @@ dependencies {
135125
addAll(configurations["api"].allDependencies)
136126
addAll(configurations["implementation"].allDependencies)
137127
addAll(configurations["compileOnly"].allDependencies)
128+
129+
add(project(":opus-jna"))
138130
}
139131

140132
testImplementation(libs.bundles.junit)
@@ -235,16 +227,6 @@ val generateJavaSources by tasks.registering(SourceTask::class) {
235227
dependsOn(sourcesForRelease)
236228
}
237229

238-
val noOpusJar by tasks.registering(ShadowJar::class) {
239-
dependsOn(shadowJar)
240-
archiveClassifier.set(shadowJar.archiveClassifier.get() + "-no-opus")
241-
242-
configurations = shadowJar.configurations
243-
from(sourceSets["main"].output)
244-
applyOpusExclusions(artifactFilters)
245-
manifest.from(jar.manifest)
246-
}
247-
248230
val minimalJar by tasks.registering(ShadowJar::class) {
249231
dependsOn(shadowJar)
250232
minimize()
@@ -337,7 +319,6 @@ tasks.build.configure {
337319
dependsOn(javadocJar)
338320
dependsOn(sourcesJar)
339321
dependsOn(shadowJar)
340-
dependsOn(noOpusJar)
341322
dependsOn(minimalJar)
342323

343324
jar.mustRunAfter(tasks.clean)
@@ -493,4 +474,3 @@ jreleaser {
493474
tasks.withType<AbstractJReleaserTask>().configureEach {
494475
mustRunAfter(tasks.named("publish"))
495476
}
496-

buildSrc/src/main/kotlin/net/dv8tion/jda/tasks/exclusions.kt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,11 @@ import org.gradle.api.provider.SetProperty
2020
import org.gradle.api.tasks.AbstractCopyTask
2121

2222
interface ArtifactFilters {
23-
val opusExclusions: SetProperty<String>
2423
val additionalAudioExclusions: SetProperty<String>
2524
}
2625

27-
fun AbstractCopyTask.applyOpusExclusions(filters: ArtifactFilters) {
28-
for (exclusion in filters.opusExclusions.get()) {
29-
exclude(exclusion)
30-
}
31-
}
32-
3326
fun AbstractCopyTask.applyAudioExclusions(filters: ArtifactFilters) {
34-
applyOpusExclusions(filters)
35-
36-
for (exclusion in filters.opusExclusions.get()) {
27+
for (exclusion in filters.additionalAudioExclusions.get()) {
3728
exclude(exclusion)
3829
}
3930
}

opus-jna/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# gradle
2+
/build/

opus-jna/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
[maven-central]: https://img.shields.io/maven-central/v/net.dv8tion/JDA-opus-jna?filter=!*-preview*&logo=apachemaven&color=blue
2+
[jitpack]: https://img.shields.io/badge/Snapshots-JitPack?logo=jitpack
3+
[installation]: #-installation
4+
[license]: https://github.com/discord-jda/JDA/tree/master/LICENSE
5+
[license-shield]: https://img.shields.io/badge/License-Apache%202.0-white.svg
6+
7+
<img align="right" src="https://github.com/discord-jda/JDA/blob/assets/assets/readme/logo.png?raw=true" height="150" width="150">
8+
9+
[![maven-central][]][installation]
10+
[![jitpack][]](https://jitpack.io/#discord-jda/JDA)
11+
[![license-shield][]][license]
12+
13+
# JDA Opus Support
14+
15+
This module enables JDA to encode and decode Opus audio. It is not necessary if your bot can handle Opus audio by itself.
16+
17+
## 🔬 Installation
18+
19+
[![maven-central][]](https://central.sonatype.com/artifact/net.dv8tion/JDA-opus-jna)
20+
[![jitpack][]](https://jitpack.io/#discord-jda/JDA)
21+
22+
This module is available on maven central. The latest version is always shown in the [GitHub Release](https://github.com/discord-jda/JDA/releases/latest).
23+
24+
The minimum java version supported by this module is **Java SE 8**.
25+
26+
> [!NOTE]
27+
> The Jitpack artifact must be retrieved using the `io.github.discord-jda.JDA` group ID and `opus-jna` as the artifact ID.
28+
29+
### Gradle
30+
31+
```gradle
32+
repositories {
33+
mavenCentral()
34+
}
35+
36+
dependencies {
37+
// There is no API to use, it is detected at runtime
38+
runtimeOnly("net.dv8tion:JDA-opus-jna:$version")
39+
}
40+
```
41+
42+
### Maven
43+
44+
```xml
45+
<dependency>
46+
<groupId>net.dv8tion</groupId>
47+
<artifactId>JDA-opus-jna</artifactId>
48+
<version>$version</version> <!-- replace $version with the latest version -->
49+
<!-- There is no API to use, it is detected at runtime -->
50+
<scope>runtime</scope>
51+
</dependency>
52+
```

opus-jna/build.gradle.kts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
plugins {
18+
`java-library`
19+
}
20+
21+
////////////////////////////////////
22+
// //
23+
// Module Configuration //
24+
// //
25+
////////////////////////////////////
26+
27+
base {
28+
archivesName.set("JDA-opus-jna")
29+
}
30+
31+
java {
32+
sourceCompatibility = JavaVersion.VERSION_1_8
33+
targetCompatibility = JavaVersion.VERSION_1_8
34+
}
35+
36+
37+
////////////////////////////////////
38+
// //
39+
// Dependency Configuration //
40+
// //
41+
////////////////////////////////////
42+
43+
repositories {
44+
mavenCentral()
45+
}
46+
47+
dependencies {
48+
49+
/* Internal dependencies */
50+
51+
// JDA
52+
implementation(rootProject)
53+
54+
//Logger
55+
implementation(libs.slf4j)
56+
57+
//Opus library support
58+
implementation(libs.opus)
59+
60+
//we use this only together with opus-java
61+
// if that dependency is excluded it also doesn't need jna anymore
62+
// since jna is a transitive runtime dependency of opus-java we don't include it explicitly as dependency
63+
implementation(libs.jna)
64+
65+
/* Annotations */
66+
67+
//Code safety
68+
compileOnly(libs.findbugs)
69+
}
70+
71+
////////////////////////////////////
72+
// //
73+
// Build Task Configuration //
74+
// //
75+
////////////////////////////////////
76+
77+
val jar by tasks.getting(Jar::class) {
78+
archiveBaseName.set(project.name + "-opus-jna")
79+
manifest.attributes("Implementation-Version" to project.version, "Automatic-Module-Name" to "net.dv8tion.jda")
80+
}
81+
82+
tasks.withType<JavaCompile> {
83+
options.encoding = "UTF-8"
84+
options.isIncremental = true
85+
86+
val args = mutableListOf("-Xlint:deprecation", "-Xlint:unchecked")
87+
88+
if (JavaVersion.current().isJava9Compatible) {
89+
args.add("--release")
90+
args.add("8")
91+
}
92+
93+
options.compilerArgs.addAll(args)
94+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
net.dv8tion.jda.internal.audio.OpusJnaCodecFactory

0 commit comments

Comments
 (0)