I have a (test) project here that we have brought a library in as a submodule (chasing down bugs features in the library). The library actually is a subdirectory in the source of a complete robot project, but I just added the library directory from the project to my build.gradle.
sourceSets {
main {
java {
srcDir 'YAGSL-Example/src/main/java'
include 'swervelib/'
}
}
}
it builds fine, but when I try to simulate on the desktop, VSCode says “Searching for main class”, then the debugger for java gives me “ConfigError: Main class ‘frc.robot.Main’ doesn’t exist in the workspace.”.
I looked at the built jar (build\libs\FRC3620_2024_Cheep-Cheep_YAGSL.jar), and there is no frc.robot.Main class in there. Actually, nothing from frc.robot… is there. looks like it built the swervelib/ only.
How do I correctly add the submodule’s swervelib/ to the build process?
Use srcDir instead of include. You can have multiple srcDir declarations in a source set.
include is actually a regex of files to include in the source set, not directories to include in the source set. By default everything is included, and then when you add an include it switches to only adding things that match that include.
I didn’t even try that because I thought it would blow up because it thought that the files in the swervelib package should be in the null package, not realizing the swervelib was the package name. worked perfectly.
spoke too soon. VSCode is happy, but a build fails.
the contents of the swervelib package are designed to be in package ‘swervelib’. gradle thinks they should be in the root package (since they are at the first level of srcdir), so I get a pile of:
The declared package "swervelib.encoders" does not match the expected package "encoders"
when doing a build.
How do I tell it to use ‘YAGSL-Example/src/main/java’ as root and compile only the swervelib directory, and use ‘src/main/java’ as a root, compiling everything?
Can you post your folder layout? I’m a bit confused on what you’re expecting it to actually be.
Each srcDir in a source set is considered as a package root. Theres not really a way around that. If you want a class to have package swervelib.encoders, that file needs to be in srcDirProvidedPath/swervelib/encoders. Thats just how Java works, theres not really a way around it.
+-------------------src-+-main-+-java-+-frc-+-robot-* <- Want this
|
+-"YAGSL-example"-+-src-+-main-+-java-+-frc-+-robot-* <- ignore this
| |
+ +-swervelib-* want this, treat as in package 'swervelib'
I want to compile everything from src/main/java, and only compile the swervelib/ folder from YAGSL-example/src/main/java.
I was hoping that the include swervelib/ would only affect the srcDir 'YAGSL-Example/src/main/java' and not the implicit srcDir src/main/java.
`
How to I tell gradle to include this ‘swervelib’ sourceset to the set of files it should compile? I’m not recognizing that in the gradle docs (I’m sure it’s in there, but I’m not seeing it).