Subproject A: Compiles a .proto file into a Java class
Subproject B: Is Kotlin code dependent on the output Java class from Subproject A in both src/main and src/test.
After building Subproject A I successfully get the Java class from the .proto. I then added the file path to the main sourceset in Subproject B like below:
sourceSets {
main {
java {
srcDirs(".../proto/main/java")
}
}
test {
java {
srcDirs(".../proto/main/java")
}
}
main successfully builds, as compileKotlin succeeds, however, the compileTestKotlin step fails with:
Cannot access class ‘…’. Check your module classpath for missing or conflicting dependencies
It is implemented in my dependencies for Subproject B
I have also tried to add it to testImplementation and it does not work either.
It seems that the src/test is not able to access the java class output from Subproject A, but src/main is? How do I give the src/test access to it so it will build? Thanks!
Actually, from reading what you wrote this sounds like a strange setup.
Shouldn’t A build source source files into class files, by having something like
sourceSets {
main {
java {
srcDir(theTaskGeneratingTheJavaSources)
}
}
}
and then B just normally depending on A not needing to reach into the other project to take source files from there?
Again, you are mixing up things. A is not generating Java classes, but Java sources.
You should not use those sources in B by hard-coding a path.
If you would really want to use the sources, that A generated within B, you should at least do it properly and safely as documented at Sharing outputs between projects.
But still, I think you should instead configure A properly to also compile those classes and then just depend on A from B. And never hard-code paths like that, especially not paths that are outputs of other tasks or even other projects.