Using a .jar for class path via gradle


I currently have a Gradle project which we use for QI purposes (running test case scenarios and such). For the same, the project is currently using the repository of the application code.
Now, we want to instead supply the team with a binary which they can use instead. I believe that wrapping the java classes and dyLibs as a .jar would be the way to go, and have been successful in creating a .jar file even tough we don’t have a main function (hence it’s not a runnable jar).
If I extract the jar into a folder, and set a path to the java files via defining sourceSets in build.gradle, it works. But I want to just define the jar file and somehow have my project directly use the files defined inside as a source set.

I have tried defining the jar as a dependency using something like:
implementation files('ecp-sdk-native/ecp-sdk-native.jar') and/or compile fileTree(dir: 'libs', include: 'mylib.jar'). Both of them didn’t work.

Any suggestions on how to proceed? Just FYI, I am not a java guy, so I don’t really get gradle / jars in depth.

Are you saying that your jar contains .java source files? If so, then as you’ve seen, the java compiler will not compile source from inside jars on the compile classpath. However, you could define your own configuration and add your dependency to it. Then write a task that goes through each of the configuration’s resolved files and extracts them into a directory. Configure a source set to include that directory. Basically you’re setting up “generated code” that is being extracted from a jar.

Hi Chris,

Thanks for the answer. I suspected as much, but was hoping for some direct method to exist.
Again, thanks for the well structured answer.