Bootstrap and Javascript libraries


(Steve Cohen) #1

Is there a recommended standard way of incorporating Javascript libraries such as Bootstrap of JQuery into a gradle project? I notice a plugins.gradle.org plugin
but its github link says it’s no longer being maintained. And I notice some old posts (2011-2013). I don’t recall reading anything and the user’s guide and searches on bootstrap and gradle tend to bring up hits that have nothing to do with the Bootstrip Javascript library.

Or am I pretty much on my own here?


(Joshua Street) #2

Gradle isn’t the first tool I normally think of when doing Javascript projects, if only because there are tools out there much more suited like NPM.

Now, if you are trying to get libraries like bootstrap for a java web project, you could look into WebJars, which are Jar’ed versions of javascript libraries that you can then link to inside Java-based templating systems like Thymeleaf and JSP. From what I’ve seen, using webjars seems to be a preferred approach to including web dependencies in a java-based web project.

Webjars.org


(Steve Cohen) #3

Thanks.

Just trying to put together a few minimal web-pages for some mostly backend systems. I wanted to achieve a look that looked a bit more current than the Fred Flintstone era. Didn’t want to just copy some Bootstrap js and css into my project but that turns out to be pretty easy to do. Quick and dirty. Thought maybe there was a better approach.


(Joshua Street) #4

Definitely check into webjars. Your use case is a shoe-in for them.


(davidmichaelkarr) #5

One viable alternative is simply to get javascript and css libraries from CDN sites. No manual download.


(Eric Wendelin) #6

Very good question, Steve.

For common libraries, a CDN is the way to go, especially if you want something as hands-free as possible. Personally, I trust Google’s Hosted Libraries for things like this, but you can also count on MaxCDN for Bootstrap, specifically.

In my experience, it is most common for Gradle users who want a little more control to leverage the Gradle Node Plugin to manage NPM dependencies. NPM is useful not just for server-side JS. Bower is the next most-popular alternative.

You point out a big flaw in our docs, especially given that JavaScript is the 4th most built language by Gradle (by total bytes across GitHub, most likely Java web apps, not node), and this is something I personally intend to rectify in the next 2 quarters.