TomDmitriev / gradle-bundle-plugin

Apache License 2.0
47 stars 24 forks source link

Support for embedded artifacts #2

Closed srs closed 9 years ago

srs commented 10 years ago

Hi.

I would really like to use this plugin, but need to be able to embed artifacts. Have created a similar plugin that does the job, but do you have any future plans for your plugin?

I could invest some time to get to know your code and create the posibility to embed artifacts like I did in our company internal plugin. It works pretty automatic (from the user's perspective) - just mark dependencies that needs to be embedded in scope 'embeddedCompile' like this:

dependencies {
    embeddedCompile 'commons-lang:commons-lang:2.4'
}

bundle {
    instruction '-exportcontents', 'org.apache.commons.lang.*'
}

So, what do you think?

TomDmitriev commented 10 years ago

Hi Sten, I am supporting this plugin and open for suggestions like the one you made. The questions I have are: 1) what are embedded artifacts? 2) how does your plugin create them?

srs commented 10 years ago

Ok, embedded dependencies does the same as Embedded-Dependency in the Felix Maven Bundle Plugin (http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html). That is, include a set of jar's inside the OSGi bundles jar.

TomDmitriev commented 10 years ago

Thanks, I see. It looks like a usable feature to me. Sure, go ahead and explore the project's code base, and if any questions come about, I will be happy to answer them.

On 17 June 2014 10:20, Sten Roger Sandvik notifications@github.com wrote:

Ok, embedded dependencies does the same as Embedded-Dependency in the Felix Maven Bundle Plugin ( http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html). That is, include a set of jar's inside the OSGi bundles jar.

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

Yours sincerely, Artyom Dmitriev

rotty3000 commented 10 years ago

I think this should be supported more natively via one of two methods in BND directly:

  1. the merge way (merges the jar directly in the the main jar):
Include-Resource: @lib/depedency.jar
  1. the Bundle classpath way (puts the jar inside and adds it to the bundles own classpath):
Bundle-Classpath: .,lib/depedency.jar
Include-Resource: lib/depedency.jar=lib/depedency.jar

So, if this plugin uses bnd directly it should already support your use case in one of these two ways.

srs commented 9 years ago

Have not had time to look at this before now. Did what @rotty3000 said and used the bnd instructions but did it more automatically. If would be nice if this could be included in the plugin if you find it useful - atleast I did. More than happy to make a pull request for it.

Here's the code I have in my build file right now.


configurations {
  embedCompile
  compile {
    extendsFrom embedCompile
  }
}

dependencies {
  embedCompile 'com.google.guava:guava:18.0'
  embedCompile 'commons-lang:commons-lang:2.4'
}

def bundleClassPath() {
    def list = ['.']
    configurations.embedCompile.each {
        list += 'OSGI-INF/lib/' + it.name
    }
    return list.join(',')
}

def includeResource() {
  def list = []
  configurations.embedCompile.each {
    list += 'OSGI-INF/lib/' + it.name + "=" + it.path
  }
  return list.join(',')
}

bundle {
  instructions << [
    '-exportcontents': 'com.google.*',
    'Bundle-ClassPath': bundleClassPath(),
    'Include-Resource': includeResource()
  ]
}

What do you think?

TomDmitriev commented 9 years ago

To be honest, I'm not sure if it's worth it given that the solution you already have looks very simple anyway. Maybe it will make more sense if more people request it.

srs commented 9 years ago

Yes, the solution is simple enough. I'm using this configuration for a couple of projects now and it seems to work fine.

rotty3000 commented 9 years ago

I've since learned there is a better instruction in bnd for this:

Conditional-Package

(FYI the new bnd docs are here http://bnd.bndtools.org)

With this instruction you simply mention the packages (you may use wildcards, do NOT use * alone however) and bnd will recursively embed the packages from the classpath analyzing them as it does so (I.e. it will craft appropriate imports)

Here's a post on the topic http://njbartlett.name/2014/05/26/static-linking.html

TomDmitriev commented 9 years ago

I'm closing the issue.