Gradle local jar dependency not working

Hi, Facing an issue with local file dependency.

This is my project configuration

Project
.
├── build.gradle
├── sub-project-1
│   ├── build.gradle
├── tests
│   ├── rest
│   └── unit
│       ├── build.gradle // Lets call this unit_build.gradle

My unit tests have a dependency on derby.jar, and the unit_build.gradle has the following:

dependencies{
	..
	testCompile fileTree(dir: "${System.getProperty('java.home')}/../db/lib", include: "derby.jar") 
    testCompile fileTree(dir: "${System.getProperty('java.home')}/../db/lib", include: "derbyclient.jar") 
}

Note: We have our own repository and derby is not included in that. So we use it by adding it from local.

This works fine when I run a gradle build, followed by my test task.

But we also publish the jar to a test server and run it there where it fails with a class not found exception on derby.

What can be the reason? What should be done to fix this?

Gradle version - 1.12

Can you try to use file rather than filetree?

You do realize that you are using an (almost to the day) 4 year old version of Gradle?

Yes, I do. But this is not my call but the orgs.

tried both testCompile and testRuntime with files instead of fileTree but same result

testRuntime files(“${System.getProperty(‘java.home’)}/…/db/lib/derby.jar”)

Works for me. Try to debug. Perhaps use a flatDir repository may help?

Clarify what you’re doing here and what isn’t found. Each built JAR only contains the classes of its own project by default. It sounds like you’re saying everything is great until you publish a JAR, but none of its dependencies.

derby.jar is not in our artifactory but we access it from JAVA_HOME path.
1)When we execute a gradle build followed by test task locally, it succeeds (so derby.jar is in classpath here)
2)We also publish the jar and execute the tests in a different server than in which it was built. The tests are failing in this step with a ClassNotFoundException on derby classes.

What I understand now is that local file dependencies are not included in the pom.xml(correct me if I am wrong)
So in (2) above, derby.jar is not in classpath.

How can I solve this?
Is there a way to include derby path location in pom.xml(by referring to JAVA_HOME env variable).
Or are there any other way to solve this?

@ddimitrov,
You mean add the folder containing derby.jar as a repository?

Rajesh, this time tried to read your posts carefully, so I can give you better answer, but I am utterly confused about what are you trying to do.

Your last post is hinting that you are building and the derby jar is there (how do you do this).

Then you run the tests in other place and the derby jar is not there (how do you do this, what is different than the first time)?

I.e. are you using Gradle both to build and run the tests? Is it the same repository you use? Do you use the Gradle test runner? Do you have any special options for the tests? If you run the tests when you build the jar do they find derby, or is it still missing? How did you declare the derby dependency (is it “compileOnly” by any chance)? Do you massage the configurations in your build file?

At this stage, the best thing you can do is provide an example project. Otherwise we are shooting in the dark.