Skip to content

Instantly share code, notes, and snippets.

@dodgex
Created November 4, 2018 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dodgex/2ea338d21fa065b27df3c1b57f3e6a23 to your computer and use it in GitHub Desktop.
Save dodgex/2ea338d21fa065b27df3c1b57f3e6a23 to your computer and use it in GitHub Desktop.
unpack webjars into version less directory
// create configuration
val webjars = configurations.create("webjar")
// add dependencies
dependencies {
"webjar"("org.webjars.bower:bootstrap:4.1.3")
"webjar"("org.webjars.bower:jquery:3.3.1")
}
// add task
task<Sync>("unzipWebjars") {
configurations["webjar"]?.files?.forEach { from(zipTree(it)) }
val webjars = configurations["webjar"]?.dependencies.orEmpty()
into("build/webjar/unzipped")
doLast {
val basePath = "${project.projectDir}/build/webjar"
webjars.forEach { webjar ->
val properties = Paths.get("$basePath/unzipped/META-INF/maven/${webjar.group}/${webjar.name}/pom.properties")
val version = Files.readAllLines(properties)
.first { it.startsWith("version=") }
.substring(8)
val files = Paths.get("$basePath/unzipped/META-INF/resources/webjars/${webjar.name}/$version")
val target = Paths.get("$basePath/${webjar.group}/${webjar.name}")
Files.createDirectories(target)
Files.walk(files)
.forEach { source ->
Files.copy(source, target.resolve(files.relativize(source)), StandardCopyOption.REPLACE_EXISTING)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment