I have a Java project here; we have the source for a library in a first level folder (it’s a git submodule).
This is part of my directory structure.
+-------------------src-+-main-+-java-+-* <- Want this
|
+-"YAGSL-example"-+-src-+-main-+-java-+-frc-* <- ignore this
| |
+ +-swervelib-* want this, treat as in package 'swervelib'
the source code in directory ‘swervelib’ is in java package ‘swervelib’, so I can’t just add that directory to the main sourceset, the resultant jar does not have those class files in the swervelib folder.
how do I include two folder trees in my java build, applying a filter to only one of them?
But the compile is failing on the files in the main project that try to import anything from swervelib; it’s like the compile is not seeing the stuff in swervelib?
sourceSets {
main {
java {
srcDir("YAGSL-Example/src/main/java/swervelib")
}
}
}
The directory structure files are in is actually irrelevant to the Java compiler, only the package statement in the source file is relevant.
That typically the directory structure is following the package naming is just usual convention and furthermore supports the spreading of the false-fact that foo.bar.baz is a “sub-package” of foo.bar which is not true, as no package hierarchy exists.
Or you could probably also just work with two source sets like
val example by sourceSets.creating {
java {
setSrcDirs(listOf("YAGSL-Example/src/main/java"))
exclude("frc")
}
}
dependencies {
implementation(example.output)
}
is there a typo in here? I tried this, but the first line throws
* Where:
Build file 'C:\Users\dwegs\Documents\2024 Code\FRC3620_2024_Cheep-Cheep_YAGSL\build.gradle' line: 133
* What went wrong:
A problem occurred evaluating root project 'FRC3620_2024_Cheep-Cheep_YAGSL'.
> Could not get unknown property 'example' for root project 'FRC3620_2024_Cheep-Cheep_YAGSL' of type org.gradle.api.Project.
I tried this, but the class files for the swervelib package ended up at the root of my final jar, instead of the swervelib folder.
Then you did something else the causes this most probably.
I checked in build/classes/java/main and there the structure was exactly like expected.
Can you maybe show an MCVE where it is not?
is there a typo in here? I tried this, but the first line throws
No, no typo.
But you copied Kotlin DSL code into a Groovy DSL file and that naturally does not compile properly.
having trouble with dependencies with the build of example, but that is another topic.
Well, it is a separate source set now, so it has separate dependency configurations.
But you could also make them extend the one from the main source set to have the same dependencies.