Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[all java] Add Java module support #7424

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rules_jvm_external_deps()
load("@rules_jvm_external//:defs.bzl", "maven_install")

maven_artifacts = [
"org.ejml:ejml-simple:0.43.1",
"org.ejml:ejml-one:0.43.1",
"com.fasterxml.jackson.core:jackson-annotations:2.15.2",
"com.fasterxml.jackson.core:jackson-core:2.15.2",
"com.fasterxml.jackson.core:jackson-databind:2.15.2",
Expand Down
3 changes: 3 additions & 0 deletions apriltag/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ dependencies {
implementation project(':wpimath')
}

apply from: "${rootDir}/shared/java/wpimath-module-patches.gradle"
apply from: "${rootDir}/shared/java/opencv-module-patches.gradle"

sourceSets {
main {
resources {
Expand Down
14 changes: 14 additions & 0 deletions apriltag/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

open module wpilib.apriltag {
requires transitive wpilib.opencv;
requires wpilib.math;
requires wpilib.util;
requires com.fasterxml.jackson.annotation;
requires com.fasterxml.jackson.databind;

exports edu.wpi.first.apriltag;
exports edu.wpi.first.apriltag.jni;
}
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ plugins {
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
id 'com.diffplug.spotless' version '6.20.0' apply false
id 'com.github.spotbugs' version '6.0.2' apply false
id 'org.javamodularity.moduleplugin' version '1.8.15' apply false
}

wpilibVersioning.buildServerMode = project.hasProperty('buildServer')
Expand All @@ -29,8 +30,10 @@ wpilibVersioning.releaseMode = project.hasProperty('releaseMode')
allprojects {
repositories {
maven {
url = 'https://frcmaven.wpi.edu/artifactory/ex-mvn'
}
url = 'https://frcmaven.wpi.edu/artifactory/ex-mvn'
}
// For testing local EJML uberjar builds
mavenLocal()
}
if (project.hasProperty('releaseMode')) {
wpilibRepositories.addAllReleaseRepositories(it)
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ repositories {
}
dependencies {
implementation "edu.wpi.first:native-utils:2025.7.1"
implementation("org.gradlex:extra-java-module-info:1.9")
implementation("org.gradlex:java-module-testing:1.5")
}
1 change: 1 addition & 0 deletions cameraserver/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ evaluationDependsOn(':cscore')
evaluationDependsOn(':hal')

apply from: "${rootDir}/shared/javacpp/setupBuild.gradle"
apply from: "${rootDir}/shared/java/opencv-module-patches.gradle"

dependencies {
implementation project(':wpiutil')
Expand Down
18 changes: 18 additions & 0 deletions cameraserver/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

/**
* The WPILib cameraserver module. This defines APIs for streaming cameras from the robot for use by
* dashboards and coprocessors, and for running OpenCV pipelines (though note that the roboRIO is
* too slow to run any but the most simple pipelines at a reasonable speed).
*/
open module wpilib.cameraserver {
requires transitive wpilib.cscore;
requires transitive wpilib.ntcore;
requires wpilib.opencv;
requires wpilib.util;

exports edu.wpi.first.cameraserver;
exports edu.wpi.first.vision;
}
1 change: 1 addition & 0 deletions cscore/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ if (OperatingSystem.current().isMacOsX()) {
}

apply from: "${rootDir}/shared/jni/setupBuild.gradle"
apply from: "${rootDir}/shared/java/opencv-module-patches.gradle"

model {
components {
Expand Down
15 changes: 15 additions & 0 deletions cscore/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

/**
* The WPILib cscore module. This defines APIs for connecting to and reading images from cameras
* connected to the robot and for configuring those cameras.
*/
open module wpilib.cscore {
requires transitive wpilib.opencv;
requires wpilib.util;

exports edu.wpi.first.cscore;
exports edu.wpi.first.cscore.raw;
}
7 changes: 7 additions & 0 deletions epilogue-processor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@ ext {
}

apply from: "${rootDir}/shared/java/javacommon.gradle"
//apply from: "${rootDir}/shared/java/opencv-module-patches.gradle"

dependencies {
implementation(project(':epilogue-runtime'))
api project(':wpilibNewCommands')

testImplementation 'com.google.testing.compile:compile-testing:+'
}

test {
moduleOptions {
runOnClasspath = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
});

roundEnv.getRootElements().stream()
.filter(e -> e instanceof TypeElement)
.filter(
e ->
processingEnv
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ public void writeEpilogueFile(
List<String> loggerClassNames, Collection<TypeElement> mainRobotClasses) {
try {
var centralStore =
m_processingEnv.getFiler().createSourceFile("edu.wpi.first.epilogue.Epilogue");
m_processingEnv.getFiler().createSourceFile("edu.wpi.first.epilogue.generated.Epilogue");

try (var out = new PrintWriter(centralStore.openOutputStream())) {
out.println("package edu.wpi.first.epilogue;");
out.println("package edu.wpi.first.epilogue.generated;");
out.println();

out.println("import static edu.wpi.first.units.Units.Seconds;");
out.println();

out.println("import edu.wpi.first.epilogue.Logged;");
out.println("import edu.wpi.first.epilogue.EpilogueConfiguration;");
out.println("import edu.wpi.first.hal.FRCNetComm;");
out.println("import edu.wpi.first.hal.HAL;");
out.println();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private void writeLoggerFile(
}

out.println("import edu.wpi.first.epilogue.Logged;");
out.println("import edu.wpi.first.epilogue.Epilogue;");
out.println("import edu.wpi.first.epilogue.generated.Epilogue;");
out.println("import edu.wpi.first.epilogue.logging.ClassSpecificLogger;");
out.println("import edu.wpi.first.epilogue.logging.EpilogueBackend;");
if (requiresVarHandles) {
Expand Down
14 changes: 14 additions & 0 deletions epilogue-processor/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

import javax.annotation.processing.Processor;

open module wpilib.epilogue.processor {
requires java.compiler;
requires jdk.compiler;
requires wpilib.epilogue;

provides Processor with
edu.wpi.first.epilogue.processor.AnnotationProcessor;
}
Loading
Loading