To bundle JS/CSS libraries similar way how we include java libraries into Spring Boot project, we can easily reference them inside build.gradle file (we are talking about Gradle based Spring Boot projects here, maven is quite similar). As an example we can include jQuery and Twitter Bootstrap into our project. To do so, simply open http://www.webjars.org/classic web site and find appropriate library and select version you require.
As we are running Gradle based project, we take gradle lib references and put them inside build.gradle the same way as we reference third party java libraries.
If we are editing Spring Boot project under IntelliJ with Gradle plugin, the project is getting updated and proper packages are downloaded and expanded. Ok, now we have both third party libraries somewhere under our project and we need to reference them in HTML. And this final part is quite easy as well. If we use Thymeleaf as a template engine, we can simply reference jQuery like this:
Everything is very straightforward and when we decide to upgrade to latest JQuery or Twitter Bootstrap after some time, we just change appropriate version number in build.gradle file.
You can find original blog post here ...
- Comments