How to include dependencies in jar?

I did something a little different - and its the only solution that currently does the job for me. The problem I was facing was the runnable jar couldn’t find the Derby database driver.

plugins {
id ‘java’
}

repositories {
jcenter()
}

dependencies {
implementation “org.apache.derby:derby:10.15.2.0” // This provides among other things org.apache.derby.iapi.jdbc.JDBCBoot
implementation “org.apache.derby:derbytools:10.15.2.0” // This provides the EmbeddedDriver
}

jar {
manifest {
attributes(
‘Main-Class’ : ‘FatDerbyJar.Main’
)
}
from {
configurations.compileClasspath.filter{ it.exists() }.collect { it.isDirectory() ? it : zipTree(it) }
}
}

1 Like