Running npm before assembling a bundle

32 views
Skip to first unread message

David Leangen

unread,
Nov 30, 2020, 12:45:52 AM11/30/20
to bndtool...@googlegroups.com
Hi!

I am having trouble figuring this out. 😩

I would like to run an npm script from gradle before assembling my jar (because I want the bundle jar to contain the built npm package resources).

However, I have not yet been able to figure out how to hook my custom task into the bnd build. (After that, getting npm to work will be my next mission.)

I am using the bnd workspace build (I think). Before I tried adding my task there was not build.gradle. Here are the contents of my settings.gradle:

----
buildscript {
repositories {
mavenCentral()
maven {
url uri(bnd_repourl)
}
}

dependencies {
classpath "biz.aQute.bnd:biz.aQute.bnd.gradle:${bnd_version}"
}

def bndPlugin = files(configurations.classpath.files)
gradle.rootProject { buildscript { dependencies { classpath bndPlugin } } }
}

apply plugin: ‘biz.aQute.bnd.workspace'
----


Any hints would be greatly appreciated!

Cheers,
=David


Hallvard Trætteberg

unread,
Nov 30, 2020, 2:34:22 AM11/30/20
to bndtool...@googlegroups.com
David,

There are several gradle plugins that can run npm scripts as gradle tasks. It shouldn't be difficult to configure make the bnd tasks depend on npm tasks, so the npm ones are performed first.

Hallvard
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/bndtools-users/5FDC36C5-0326-4259-93AF-ED0A742DE1B9%40gmail.com.


Peter Kriens

unread,
Nov 30, 2020, 2:36:51 AM11/30/20
to via bndtools-users
There are two alternatives to doing this in Gradle. Advantage is that you do not have to go to the command line but can stay in Eclipse. The -generate instruction does a time/date check and executes an External Plugin or external system command: https://bnd.bndtools.org/instructions/generate.html.

If the job takes too much time for interactive use (building a single page web app, even a single one, takes a staggering amount of time imho) then you can macros to only run it at batch time.

Kind regards,

Peter Kriens

David Leangen

unread,
Nov 30, 2020, 4:07:36 AM11/30/20
to bndtool...@googlegroups.com

Thank you for the replies.

@ Hallvard
> There are several gradle plugins that can run npm scripts as gradle tasks. It shouldn't be difficult to configure make the bnd tasks depend on npm tasks, so the npm ones are performed first.

I totally agree, it SHOULDN’T be hard. 😀

I want to make the ‘assemble' task depend on myTask, so I tried what is written in the gradle docs, i.e.:

assemble.dependsOn myTask

But:

> Could not get unknown property 'assemble' for root project ‘[PROJECT]' of type org.gradle.api.Project.

And so the rabbit hole starts, trying to figure out how the heck to get a handle on one of the bnd tasks. Hence my question. I think maybe there is something going on here about the way the bnd plugin works that I am not yet understanding. Or maybe just gradle plugins in general, I don’t know. For all the time I’ve been using OSGi I usually don’t have to look at gradle so even 2 or 3 years when I actually do I can never commit it to my (ever decreasing) memory. BJ is the gradle master around here, AFAIK.


@Peter
> There are two alternatives to doing this in Gradle. Advantage is that you do not have to go to the command line but can stay in Eclipse. The -generate instruction does a time/date check and executes an External Plugin or external system command: https://bnd.bndtools.org/instructions/generate.html.
>
> If the job takes too much time for interactive use (building a single page web app, even a single one, takes a staggering amount of time imho) then you can macros to only run it at batch time.

Thanks! I forgot about the -generate instruction. I’ll give that a try. I’ve been meaning to take a look anyway.


Cheers,
=David


Michael Lipp

unread,
Nov 30, 2020, 4:09:50 AM11/30/20
to bndtool...@googlegroups.com
You can find some examples for this approach in this project
(https://github.com/mnlipp/jgrapes-webconsole). Search for "NodeTask" in
the *.gradle files.

 - Michael

Am 30.11.20 um 08:34 schrieb Hallvard Trætteberg:

David Leangen

unread,
Nov 30, 2020, 4:21:38 AM11/30/20
to bndtool...@googlegroups.com

You can find some examples for this approach in this project
(https://github.com/mnlipp/jgrapes-webconsole). Search for "NodeTask" in
the *.gradle files.

Thanks!

There’s a lot going on there, and the layout is very different from my (very simple) bnd workspace, but it looks like there is a lot to learn from this. I will definitely take a look.

Cheers,
=David


David Leangen

unread,
Nov 30, 2020, 6:05:30 AM11/30/20
to bndtool...@googlegroups.com

Just to close this topic, in case there are any other impatient people like me out there in the Googleverse. 😂

I was not able to figure out the syntax to make a system call with -generate, so I’ll have to give it a go some other time. (Still very interested as I can see the utility for several use cases.)

I still don’t understand how to bind to a bnd task, but it doesn’t matter. Setting `compileJava.dependsOn myTask` works fine.


The jgrapes examples put me in the right direction.

Thanks to all! You saved me a TON of time. And beer.


Cheers,
=David


BJ Hargrave

unread,
Nov 30, 2020, 1:45:32 PM11/30/20
to bndtool...@googlegroups.com
If you want to make sure your npm-running task runs before the jar task, then you want to make sure the jar task dependsOn the npm-running task. The npm-running task can then make any desired changes to the inputs to be used by the jar task. There is nothing Bnd specific about this advice.

--
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.


--

BJ

David Leangen

unread,
Nov 30, 2020, 8:09:16 PM11/30/20
to bndtool...@googlegroups.com

> If you want to make sure your npm-running task runs before the jar task, then you want to make sure the jar task dependsOn the npm-running task. The npm-running task can then make any desired changes to the inputs to be used by the jar task. There is nothing Bnd specific about this advice.

Thanks BJ, yes I see that now, and I got it working. (embarrassed)

The great thing about bnd is that it just works. I only have to edit my bnd files and everything is groovy without worrying about Gradle. The functionality available from bnd is extremely powerful.

The tough thing is that it works so well, I almost forget Gradle is even there. I checked: I only touch gradle once about every 4~5 years. It’s never enough for me to actually get it in my tiny head, especially some of the more magical parts.

Thanks as always for humoring me and helping me out. 😀


Cheers,
=David


Reply all
Reply to author
Forward
0 new messages