Gradle osgi build with spring dm

Hi,

I am using the latest gradle (1.0-rc3) and I am having trouble with the osgi build picking up the spring dm files. In my maven project, the maven-bundle-plugin will use the spring files to populate the Import-Package by default. (I believe bnd does this by default, but not sure) However, I can’t seem to get the same thing working with the gradle osgi plugin. Any ideas? I must be doing something wrong I’m sure.

Roshan

Can you post the build script you have so far?

Sure, Here is my subproject gradle file:

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'osgi'
   dependencies {
    compile(project(':accumulo.myproj'))
}
  jar {
    manifest { // the manifest of the default jar is of type OsgiManifest
        instruction 'Import-Package', '*'
    }
}

My build.gradle

allprojects {
    group = 'proj'
    version = '2.0.0-SNAPSHOT'
      buildDir = "target"
}
  subprojects {
    apply plugin: 'maven'
 apply plugin: 'java'
}

My settings.gradle

include 'accumulo.myproj'
include 'myproj'
  rootProject.children.each { project ->
  project.buildFileName = "${project.name}.gradle"
  assert project.projectDir.isDirectory()
  assert project.buildFile.isFile()
}

Update: Added code tags

That build doesn’t declare any dependencies. I probably need to see ‘’:accumulo.mypro’.

Also, when you post, please wrap code in <code> tags.

<code> Code goes here. </code>

Sure thing, here is accumulo.myproj:

apply plugin: 'java'
apply plugin: 'maven'
  dependencies {
  compile(libraries.accumulo_core)
  compile(libraries.slf4j_log4j12)
  compile(libraries.zookeeper)
}

I defined the libraries in build.gradle, but didn’t want to add the huge list to the post.

Are you declaring a ‘repositories {}’ block anywhere?

I also need to see a sample of your dependency definitions.

Sure, no repositories as of yet, here is the libraries block:

def accumulo_version = '1.4.0'
libraries = [
//accumulo
        accumulo_core: "org.apache.accumulo:accumulo-core:${accumulo_version}",
        slf4j_log4j12: "org.slf4j:slf4j-log4j12:1.5.8",
          //zk
        zookeeper: "org.apache.zookeeper:zookeeper:3.3.0"
]

Does something stick out as to why the osgi plugin might not be picking up the packages in the spring files? I have the spring files located in src/main/resources/META-INF/spring/

The no repositories block is the problem. Gradle doesn’t implicitly use Maven Central like Maven.

Add:

repositories {
  mavenCentral()
}

Hmm no luck. So to make things much easier, I started a new osgi project to test. I ran the maven build with the typical maven-bundle-plugin set up, and it picked up the classes properly to import from the spring-dm files. However, when I ran the gradle script, the Manifest came out different. Here is the gradle script:

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'osgi'
  group = 'tst'
version = '1.0.0-SNAPSHOT'
  repositories {
    mavenCentral()
}
  dependencies {
    compile("org.apache.accumulo:accumulo-core:1.4.0")
}
  jar {
    manifest {
        instruction 'Import-Package', '*'
        instruction 'Export-Package', '*'
    }
}

I think I’m going to try bnd directly and see if that picks up the spring-dm files. (It probably isn’t a gradle problem if the osgi plugin just delegates to bnd)

The OSGI plugin does delegate to BND to generate the manifest.