TomDmitriev / gradle-bundle-plugin

Apache License 2.0
47 stars 24 forks source link

Unwanted Jars are sent to Bnd from bundle-plugin #43

Closed xtracoder closed 8 years ago

xtracoder commented 8 years ago

After digging deeper into problem here (https://github.com/bndtools/bnd/issues/1276) I've found that problem partially comes from this gradle-bundle-plugin - implementation actually sends all transitive dependencies to Bnd, not the ones explicitly defined in build configuration. This, of course, has no sense for building of the bundle. Such behavior occurs at least with Gradle 2.9.

    static File[] getClasspath(Jar jarTask) {
        def project = jarTask.project
        def configuration = project.configurations.runtime.copyRecursive()
        def excludeDependencies = project.bundle.excludeDependencies
        excludeDependencies.each {
            configuration.exclude(it)
        }
        configuration.files
    }

more appropriate implementation is as of now

    static File[] getClasspath(Jar jarTask) {
        def project = jarTask.project
        def configuration = project.configurations.runtime.copyRecursive()
        def excludeDependencies = project.bundle.excludeDependencies
        def classPath = []

        project.configurations.runtime.resolvedConfiguration.firstLevelModuleDependencies.each { dependency -> 
            dependency.moduleArtifacts.each { artifact ->
                classPath << artifact.file
            }
        }

        classPath
    }

Additionally, doc/readme says

Exclusion of dependencies from the classpath passed to Bnd
bundle {
    exclude module: 'guava'
    exclude group: 'org.jmock'
}

according to Gradle's docs ( https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/Configuration.html#exclude(java.util.Map) ) this works only for transient dependencies and does not work for dependencies defined in 'compile' or 'runtime' configuratons.

TomDmitriev commented 8 years ago

@xtracoder, hmm, I don't know why they put that into the docs, you can actually check that it works not only for transient dependencies.

On 20 December 2015 at 21:18, xtracoder notifications@github.com wrote:

After digging deeper into problem here ( https://githubcom/bndtools/bnd/issues/1276) I've found that problem partially comes from this gradle-bundle-plugin - implementation actually sends all transitive dependencies to Bnd, not the ones explicitly defined in build configuration This, of course, has no sense for building of the bundle Such behavior occurs at least with Gradle 29

static File[] getClasspath(Jar jarTask) {
    def project = jarTaskproject
    def configuration = projectconfigurationsruntimecopyRecursive()
    def excludeDependencies = projectbundleexcludeDependencies
    excludeDependencieseach {
        configurationexclude(it)
    }
    configurationfiles
}

more appropriate implementation is as of now

static File[] getClasspath(Jar jarTask) {
    def project = jarTaskproject
    def configuration = projectconfigurationsruntimecopyRecursive()
    def excludeDependencies = projectbundleexcludeDependencies
    def classPath = []

    projectconfigurationsruntimeresolvedConfigurationfirstLevelModuleDependencieseach { dependency ->
        dependencymoduleArtifactseach { artifact ->
            classPath << artifactfile
        }
    }

    classPath
}

Additionally, doc/readme says

Exclusion of dependencies from the classpath passed to Bnd bundle { exclude module: 'guava' exclude group: 'orgjmock' }

according to Gradle's docs ( https://docsgradleorg/current/javadoc/org/gradle/api/artifacts/Configurationhtml#exclude(javautilMap) ) this works only for transient dependencies and does not work for dependencies defined in 'compile' or 'runtime' configuratons

— Reply to this email directly or view it on GitHub https://github.com/TomDmitriev/gradle-bundle-plugin/issues/43.

Yours sincerely, Artyom Dmitriev

xtracoder commented 8 years ago

Re: you can actually check that it works not only for transient dependencies.

Yes, it does work. Most probably i've made a 'typo' or so when experimenting and it was not excluded in my test.