Shadowjar dependency to include a local jar file

I’m new to gradle and I’m using Gradle 5.6.4.

I added a new api jar to the existing project, which was rather simple, and the project builds successfully. But I’m not finding any clear documentation on how to have it include a local jar file as shadowjar dependency. The jar file’s classes are not being added to the build artifact jar file.

What is the correct include format to specify a local jar file that was included in the dependencies section? If include is not the correct way to do this, what is?

dependencies {
    implementation 'org.apache.commons:commons-lang3:3.9'
    implementation 'com.google.code.gson:gson:2.8.6'
    compileOnly fileTree(dir: 'lib', include: ['*.jar'])
}
shadowJar {
    dependencies {
        include(dependency('org.apache.commons:commons-lang3:3.9'))
        include(dependency('com.google.code.gson:gson:2.8.6'))
        // Need to know the following include to use with jar files:
        include( jar??: 'lib/FunctionalAPI-7.4.3.jar')
    }
}
build.dependsOn(shadowJar)

Thanks for your help and consideration,
rBlue

I figured something out. I am able to generate a build artifact that works now.

My original question has not been answered pertaining to including local jar files in the shadowJar includes with the include statements.

These are the change that I had to make. Basically since I was using the local jar as a compileOnly dependency, it could not be added to the build artifact. So I excluded that jar from the “others” and made it a normal compile and then it’s classes appeared in the build artifact.

dependencies {
    implementation 'org.apache.commons:commons-lang3:3.9'
    implementation 'com.google.code.gson:gson:2.8.6'
    compileOnly fileTree(dir: 'lib', include: ['*.jar'], exclude: ['FunctionalAPI-7.4.3.jar'])
    compile fileTree(dir: 'lib', include: ['FunctionalAPI-7.4.3.jar'])
}
shadowJar {
    dependencies {
        include(dependency('org.apache.commons:commons-lang3:3.9'))
        include(dependency('com.google.code.gson:gson:2.8.6'))
    }
}
build.dependsOn(shadowJar)

I guess there is no solution to specifying a local jar within the shadowJar dependency include? I guess not. Thanks everyone for the numerous replies. :wink: