How to add Transitive dependancies to local jar ** I don't want to create fat jar**

Hi,

I have generated jar file with below task. and this jar file I will be using as a local jar to another project.

 
jar {
    from('src/main/resources') {
        include '*.properties'
    }
    manifest {
        attributes(
                'Main-Class': "main",
                'Built-By'       : System.properties['user.name'],
                'Build-Timestamp': new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date()),
                'Build-Revision' : versioning.info.commit,
                'Created-By'     : "Gradle ${gradle.gradleVersion}",
                'Build-Jdk'      : "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})",
                'Build-OS'       : "${System.properties['os.name']} ${System.properties['os.arch']} ${System.properties['os.version']}",
                "Class-Path": configurations.compile.collect { it.getName() }.join(' ')
        )
    }
}

I have added as dependency in build.gradle in another gradle project as below

compile files('libs/abc-0.0.10-SNAPSHOT.jar')

However, it is not downloading dependancies from mavencentral present in the jar. I have to all dependencies again in new gradle project.

So am I missing anything while creating jar?? or do i need to add any configurations to download from maven central??

Please Note: ** I don’t want to create fat jar**, as the size of jar is huge.

This is a file dependency. A file dependency is specifically a binary file on disk without any metadata such as dependencies.

There’s no way to download dependencies from just a JAR file. If you just have a JAR file, you must declare any dependencies that it needs.

You need metadata in order to have dependencies resolved from Maven Central. This metadata is normally contained in a POM file as there are no dependencies from Maven Central present in the JAR file itself.

It is not possible to provide this POM with a file dependency or flatDir repository even if you publish it with the JAR file. You would need to have a folder on disk that is structured and configured as a Maven repository, even if it is on your local file system.

Thanks James.

But how the jars downloaded from maven-repository are downloading their transitive dependancies?
Any idea how to create maven repository structure along with POM

It’s not just the JARs that are downloaded. The POM file is downloaded for every resolved dependency from a Maven repository. The POM contains the dependencies. This continues recursively for each dependency encountered.

This is covered in the Maven Publishing section of the user guide.