'How do I build a fat jar (bundle) with Bndtools in a Gradle project?

I am currently trying to create a bundle with bnd in a Gradle project.

The idea was to try getting the list of jar dependencies with Gradle and modify the jar task to add the libs inside the bundle.

Let's say, I would like to remove the includeresource.

-includeresource: lib/jsoup.jar=jsoup-1.14.3.jar
Bundle-ClassPath: ., lib/jsoup.jar

I tried some variations of:

jar {
    duplicatesStrategy = 'EXCLUDE'
    from {
        configurations.runtimeClasspath.findAll {
            it.name.endsWith('jar')
        }.collect { println it.name; zipTree(it) }
    }
}

I can see the name of the jar being printed, but not included inside the bundle, (I know zipTree would expand).

Suggestions from https://discuss.gradle.org/t/how-to-include-dependencies-in-jar/19571/16 do not seem to be valid for bnd, and I suspect bnd overrides the jar task somehow.

A suggestion as:

jar {
    def libBuildDir = mkdir "${buildDir}/resources/main/lib"
    copy {
        from { configurations.jarLibs }
        into { libBuildDir }
    }
}

Would be perfect, but it does not seem to work for bundles. Any ideas?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source