Skip to content

gradle doesn't pick up junit dependency #1457

@pdkovacs

Description

@pdkovacs

Describe the bug
Running ./gradlew build results in junit import errors:

/home/pkovacs/github/TooTallNate/Java-WebSocket/src/test/java/org/java_websocket/exceptions/InvalidEncodingExceptionTest.java:28: error: package org.junit.jupiter.api does not exist
import org.junit.jupiter.api.Test;
...

To Reproduce
Steps to reproduce the behavior:

  1. Run ./gradlew build

Example application to reproduce the issue
https://github.com/TooTallNate/Java-WebSocket

Expected behavior
Accept imports, run the tests

Debug log
N/A

Environment(please complete the following information):

  • Version used: 1ed042e
  • Java version: Java 8, Java 21
  • Operating System and version: Linux blr9 6.11.0-17-generic #17~24.04.2-Ubuntu SMP PREEMPT_DYNAMIC Mon Jan 20 22:48:29 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
  • Endpoint Name and version: N/A
  • Link to your project: N/A

Additional context
The following changes to build.gradle fix the issue:

diff --git a/build.gradle b/build.gradle
index 3c47235..3306ad4 100644
--- a/build.gradle
+++ b/build.gradle
@@ -39,3 +39,8 @@ dependencies {
     testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '2.0.15'
-    testImplementation group: 'org.junit', name: 'junit-bom', version: '5.11.4', ext: 'pom'
+    testImplementation 'org.junit.jupiter:junit-jupiter:5.9.2'
+}
+
+tasks.named('test') {
+    // Use JUnit Platform for unit tests.
+    useJUnitPlatform()
 }

(I am not creating a PR, because the patch above reflects how I create my java projects for use with gradle, but I am not a gradle-expert, so I may be missing something.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions