Resolve group and name in Gradle non-workspace build

38 views
Skip to first unread message

Marc Schlegel

unread,
Apr 4, 2017, 4:36:07 PM4/4/17
to bndtools-users
I am working on a little PR for the kafka-clients module which currently doesnt provide OSGi metadata.

After applying the biz.aQute.bnd.builder which worked as expected. The last missing thing is the bsn which I would like to overwrite in the bnd-file. When using a Maven build I can write the following to resolve variables from Maven

Bundle-SymbolicName: ${project.groupId}.${project.artifactId}

I cannot find the documentation what the correct placeholder are for a non-workspace Gradle build. 

regards
Marc

BJ Hargrave

unread,
Apr 4, 2017, 4:53:44 PM4/4/17
to bndtool...@googlegroups.com
If you set the Bundle-Name header in the jar.manifest DSL, you will have full access to the Gradle project properties.

The Bnd Gradle plugin for non-workspace build does not make the Gradle project properties available to the Bnd Builder. Not sure if that is a good idea or not... Hmmm....


--
You received this message because you are subscribed to the Google Groups "bndtools-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bndtools-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
BJ

BJ Hargrave

unread,
Apr 4, 2017, 5:05:03 PM4/4/17
to bndtool...@googlegroups.com
You can pass any desire gradle properties into the Bnd Builder using the jar.manifest DSL.

jar {
    manifest {
        attributes('-groupid': group.toString(),
                   'artifactId': archivesBaseName)
    }
}

You can then reference those variables in your bnd file.

Bundle-SymbolicName: ${-groupid}.${artifactId}

Note: I used -groupid since that is the Bnd convention and it uses in the pom generation code as the groupId if not otherwise specified.

Many Gradle project/task properties have non-String values, while all Bnd properties are Strings. So it would require special handling to flatten them to Strings.

--
BJ

Marc Schlegel

unread,
Apr 4, 2017, 5:24:54 PM4/4/17
to bndtools-users
As always, thank you very much BJ

Unfortunately in Kafka the group is specified within gradle.properties which is not yet set when creating the attributes. Currently it results in a bsn "build.kafka-clients" rather than "org.apache.kafka.kafka-clients". 

BJ Hargrave

unread,
Apr 4, 2017, 5:29:50 PM4/4/17
to bndtool...@googlegroups.com
Properties from gradle.properties are available during task configuration. So you can easily reference them in the jar task configuration.

Marc Schlegel

unread,
Apr 4, 2017, 5:32:47 PM4/4/17
to bndtools-users
Found the mistake: I had to use project.group.toString() instead of just group.toString()

BJ Hargrave

unread,
Apr 4, 2017, 5:34:32 PM4/4/17
to bndtool...@googlegroups.com
Ah, yes, task.group is completely different :-)

Marc Schlegel

unread,
Apr 4, 2017, 5:46:33 PM4/4/17
to bndtools-users
Well, PR is created [1]. Lets hope it gets accepted so I dont have to create some wrapping artifact :-)

Thanks again for the help and the nice documentation about the Gradle plugin

[1] https://github.com/apache/kafka/pull/2807

BJ Hargrave

unread,
Apr 4, 2017, 7:07:43 PM4/4/17
to bndtool...@googlegroups.com
So I ended up adding support for access to gradle properties in the bnd file. See https://github.com/bndtools/bnd/pull/1982

It was not as hard as I thought.

This will be in 3.4.
Reply all
Reply to author
Forward
0 new messages