Bower Installer Gradle Plugin
Note
|
This plugin has been officially replaced with the client dependencies gradle plugin. |
The Gradle plugin uses bower-installer to manage client-side dependencies alongside the other dependencies in build.gradle.
Getting Started
plugins {
id 'com.craigburke.bower-installer' version '2.5.1'
}
Tasks
The plugin adds the following tasks to your build:
Task |
Description |
bowerInstall |
Installs all the bower dependencies you have set in your build.gradle |
bowerRefresh |
Refreshes bower dependencies (if you add or modify your bower configuration) |
bowerClean |
Removes bower dependencies and clears Bower’s cache |
Configuration
You can specify dependencies as well as control where files are installed to with the provided dependency DSL.
plugins {
id 'com.craigburke.bower-installer' version '2.5.1'
}
bower {
installBase = 'src/assets/bower' // <1>
'angular'('1.3.x') {
source 'angular.js' // <2>
}
'angular-animate'('1.3.x') {
source 'angular-animate.js' >> '/angular/modules/' // <3>
}
'ui-router'('0.2.x') // <4>
'bootstrap'('3.3.x') {
source 'dist/css/*.min.css' >> 'styles/'
source 'dist/fonts/**' >> 'fonts/'
excludes 'jquery' // <5>
}
'animate.css'('https://github.com/daneden/animate.css.git') // <6>
}
-
installBase is the base path that the bower dependencies are installed to
-
This copies the angular.js file to the default location (
src/assets/bower/angular/angular.js
) -
An absolute path is used here so
angular-animate.js
will be copied tosrc/assets/bower/angular/modules/angular-animate.js
-
When no sources are specified the default behavior of bower-installer determines which files are included
-
Exclude the transitive dependency jquery
-
Use a git repository as a dependency source
Note
|
if installBase is not set, it defaults to src/assets/bower or grails-app/assets/bower in a Grails 3 application. |
Adding Dependencies
By default, bower-installer will install only the main files listed in that project’s bower.json file.
Sometimes you need additional files that aren’t listed as the main files. In cases like that first start by including the entire reposistory:
bower {
'bootstrap'('3.3.x') {
source '**' // (1)
}
}
-
This installs all the files within the bootstrap repo to
src/assets/bower/bootstrap/
From there you can be more selective about what files you actually want installed and where
bower {
'bootstrap'('3.3.x') {
source 'dist/**' // (1)
}
}
-
This installs everything contained within the dist folder (including subfolders) into
src/assets/bower/bootstrap/
Note
|
Every time you make a changes to your bower dependencies you must run the bowerRefresh task. |
Advanced Configuration
bower {
additional = [ // (1)
name: 'gradle-bower-installer'
]
}
-
additional allow you to set optional properties in the generated bower.json file.
Troubleshooting
If you set the bowerDebug property when you run bowerInstall then you’ll get more detailed output and both the bower.json
file and the bower_components
folder will remain to help troubleshoot.
./gradlew bowerInstall -PbowerDebug=true
Contributions
Thank you to the following people who have made major contributions in terms of both feedback and code: