Skip to content

Instantly share code, notes, and snippets.

@spikeheap
Last active April 11, 2020 19:05
Gradle build script to install NodeJS packages and Bower dependencies. This assumes you create package.json (nodejs) and bower.json files in the root of your project.
import org.gradle.api.tasks.Exec
defaultTasks 'bower'
// Get the path for the locally installed binaries
task npmBin << {
new ByteArrayOutputStream().withStream { os ->
def result = exec {
executable = 'npm'
args = ['bin']
standardOutput = os
}
ext.binPath = os.toString().trim() + "/"
}
}
// Install packages from package.json
task npm(type: Exec) {
description = "Grab NodeJS dependencies (from package.json)"
commandLine = ["npm", "install"]
inputs.file "package.json"
outputs.dir "node_modules"
tasks.npmBin.execute()
}
// Install the bower components for front-end library management
task bower(dependsOn: 'npm', type: Exec){
commandLine "${npmBin.binPath}bower", 'install'
}
@pacey
Copy link

pacey commented Oct 9, 2014

Thanks for the initial code to solve this problem. We ran into issues on Windows and have found an OK work-around :) https://gist.github.com/pacey/54278ecd716e82b16f14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment