Gradle/SBTでAdminLTEを管理する

# 概要
もともと独自タスクで定義していたものを **WebJars** に置き換えました。

各ビルドツールの使用バージョンは以下のとおりです。

- Gradle : 3.2.1
- SBT ： 0.13.11

# Gradle（独自タスク）
```groovy:build.gradle
task downloadAdminLTECssFontsJs << {
	def staticDirPath = 'src/main/resources/static'
	def workDirPath = 'work'

	// Delete Work Directory
	clearDir("${workDirPath}")
	// Bootstrap & AdminLTE Dashboard & Control Panel Template
	downloadAdminLTE("2.3.8", "2.2.3", "${workDirPath}", "${staticDirPath}")
	// Font Awesome Icons
	downloadFontAwesome("4.7.0", "${workDirPath}", "${staticDirPath}")
	// Ionicons
	downloadIonicons("2.0.1", "${workDirPath}", "${staticDirPath}")
	// html5shiv.js
	downloadHtml5shivJs("3.7.3", "${workDirPath}", "${staticDirPath}")
	// respond.min.js
	downloadRespondMinJs("1.4.2", "${workDirPath}", "${staticDirPath}")
	// Delete Work Directory
	clearDir("${workDirPath}")
}


void clearDir(String dirPath) {
	delete dirPath
}
void downloadAdminLTE(String adminLTEVersion, String jQueryVersion, String workDirPath, String staticDirPath) {
	download {
		src "https://codeload.github.com/almasaeed2010/AdminLTE/zip/v${adminLTEVersion}"
		dest new File("${workDirPath}/download/AdminLTE-${adminLTEVersion}.zip")
	}
	copy {
		from zipTree("${workDirPath}/download/AdminLTE-${adminLTEVersion}.zip")
		into "${workDirPath}/unzip"
	}
	copy {
		from "${workDirPath}/unzip/AdminLTE-${adminLTEVersion}/bootstrap/css"
		into "${staticDirPath}/css"
	}
	copy {
		from "${workDirPath}/unzip/AdminLTE-${adminLTEVersion}/bootstrap/fonts"
		into "${staticDirPath}/fonts"
	}
	copy {
		from "${workDirPath}/unzip/AdminLTE-${adminLTEVersion}/bootstrap/js"
		into "${staticDirPath}/js"
	}
	copy {
		from "${workDirPath}/unzip/AdminLTE-${adminLTEVersion}/dist/css"
		into "${staticDirPath}/css"
	}
	copy {
		from "${workDirPath}/unzip/AdminLTE-${adminLTEVersion}/dist/img"
		into "${staticDirPath}/img"
	}
	copy {
		from "${workDirPath}/unzip/AdminLTE-${adminLTEVersion}/dist/js"
		into "${staticDirPath}/js"
	}
	copy {
		from "${workDirPath}/unzip/AdminLTE-${adminLTEVersion}/plugins/jQuery/jquery-${jQueryVersion}.min.js"
		into "${staticDirPath}/js"
	}
	copy {
		from "${workDirPath}/unzip/AdminLTE-${adminLTEVersion}/plugins"
		into "${staticDirPath}/plugins"
	}
	delete "${staticDirPath}/js/pages"
	delete "${staticDirPath}/js/demo.js"
	delete "${staticDirPath}/plugins/jQuery"
}
void downloadFontAwesome(String fontAwesomeVersion, String workDirPath, String staticDirPath) {
	download {
		src "http://fortawesome.github.io/Font-Awesome/assets/font-awesome-${fontAwesomeVersion}.zip"
		dest new File("${workDirPath}/download/font-awesome-${fontAwesomeVersion}.zip")
	}
	copy {
		from zipTree("${workDirPath}/download/font-awesome-${fontAwesomeVersion}.zip")
		into "${workDirPath}/unzip"
	}
	copy {
		from "${workDirPath}/unzip/font-awesome-${fontAwesomeVersion}/css/font-awesome.min.css"
		into "${staticDirPath}/css"
	}
	copy {
		from "${workDirPath}/unzip/font-awesome-${fontAwesomeVersion}/fonts"
		into "${staticDirPath}/fonts"
	}
}
void downloadIonicons(String ioniconsVersion, String workDirPath, String staticDirPath) {
	download {
		src "https://codeload.github.com/driftyco/ionicons/zip/v${ioniconsVersion}"
		dest new File("${workDirPath}/download/ionicons-${ioniconsVersion}.zip")
	}
	copy {
		from zipTree("${workDirPath}/download/ionicons-${ioniconsVersion}.zip")
		into "${workDirPath}/unzip"
	}
	copy {
		from "${workDirPath}/unzip/ionicons-${ioniconsVersion}/css/ionicons.min.css"
		into "${staticDirPath}/css"
	}
	copy {
		from "${workDirPath}/unzip/ionicons-${ioniconsVersion}/fonts"
		into "${staticDirPath}/fonts"
	}
}
void downloadHtml5shivJs(String html5shivJsVersion, String workDirPath, String staticDirPath) {
	download {
		src "https://oss.maxcdn.com/html5shiv/${html5shivJsVersion}/html5shiv.min.js"
		dest new File("${workDirPath}/download/html5shiv.min.js")
	}
	copy {
		from "${workDirPath}/download/html5shiv.min.js"
		into "${staticDirPath}/js"
	}
}
void downloadRespondMinJs(String respondMinJsVersion, String workDirPath, String staticDirPath) {
	download {
		src "https://oss.maxcdn.com/respond/${respondMinJsVersion}/respond.min.js"
		dest new File("${workDirPath}/download/respond.min.js")
	}
	copy {
		from "${workDirPath}/download/respond.min.js"
		into "${staticDirPath}/js"
	}
}
```

# SBT（独自タスク）
```build.sbt
lazy val downloadAdminLTECssFontsJs = taskKey[Unit]("Download AdminLTE Template.")

downloadAdminLTECssFontsJs := {
  val staticDir = file("public")
  val workDir = file("work")
  println("AdminLTE Downloading...")

  // Delete Work Directory
  cleanDir(workDir)
  cleanDir(staticDir)
  // Bootstrap & AdminLTE Dashboard & Control Panel Template
  downloadAdminLTE("2.3.8","2.2.3",workDir,staticDir)
  // Font Awesome Icons
  downloadFontAwesome("4.7.0",workDir,staticDir)
  // Ionicons
  downloadIonicons("2.0.1",workDir,staticDir)
  // html5shiv.js
  downloadHtml5shivJs("3.7.3",workDir,staticDir)
  // respond.min.js
  downloadRespondMinJs("1.4.2",workDir,staticDir)
  // Delete Work Directory
  cleanDir(workDir)

  println("AdminLTE Download Done.")
}

def cleanDir(dir: File) = IO.delete(dir)
def downloadAdminLTE(adminLTEVersion: String, jQueryVersion: String, workDir: File, staticDir: File) = {
  IO.unzipURL(new URL(s"https://codeload.github.com/almasaeed2010/AdminLTE/zip/v${adminLTEVersion}"),workDir/"unzip")
  IO.copyDirectory(workDir/s"unzip/AdminLTE-${adminLTEVersion}/bootstrap/css",staticDir/"css")
  IO.copyDirectory(workDir/s"unzip/AdminLTE-${adminLTEVersion}/bootstrap/fonts",staticDir/"fonts")
  IO.copyDirectory(workDir/s"unzip/AdminLTE-${adminLTEVersion}/bootstrap/js",staticDir/"js")
  IO.copyDirectory(workDir/s"unzip/AdminLTE-${adminLTEVersion}/dist/css",staticDir/"css")
  IO.copyDirectory(workDir/s"unzip/AdminLTE-${adminLTEVersion}/dist/img",staticDir/"img")
  IO.copyDirectory(workDir/s"unzip/AdminLTE-${adminLTEVersion}/dist/js",staticDir/"js")
  IO.copyFile(workDir/s"unzip/AdminLTE-${adminLTEVersion}/plugins/jQuery/jquery-${jQueryVersion}.min.js",staticDir/s"js/jquery-${jQueryVersion}.min.js")
  IO.copyDirectory(workDir/s"unzip/AdminLTE-${adminLTEVersion}/plugins",staticDir/"plugins")
  IO.delete(staticDir/"js/pages")
  IO.delete(staticDir/"js/demo.js")
  IO.delete(staticDir/"js/plugins/jQuery")
}
def downloadFontAwesome(fontAwesomeVersion: String, workDir: File, staticDir: File) = {
  IO.unzipURL(new URL(s"http://fortawesome.github.io/Font-Awesome/assets/font-awesome-${fontAwesomeVersion}.zip"),workDir/"unzip")
  IO.copyFile(workDir/s"unzip/font-awesome-${fontAwesomeVersion}/css/font-awesome.min.css",staticDir/"css/font-awesome.min.css")
  IO.copyDirectory(workDir/s"unzip/font-awesome-${fontAwesomeVersion}/fonts",staticDir/"fonts")
}
def downloadIonicons(ioniconsVersion: String, workDir: File, staticDir: File) {
  IO.unzipURL(new URL(s"https://codeload.github.com/driftyco/ionicons/zip/v${ioniconsVersion}"),workDir/"unzip")
  IO.copyFile(workDir/s"unzip/ionicons-${ioniconsVersion}/css/ionicons.min.css",staticDir/"css/ionicons.min.css")
  IO.copyDirectory(workDir/s"unzip/ionicons-${ioniconsVersion}/fonts",staticDir/"fonts")
}
def downloadHtml5shivJs(html5shivJsVersion: String, workDir: File, staticDir: File) {
  IO.download(new URL(s"https://oss.maxcdn.com/html5shiv/${html5shivJsVersion}/html5shiv.min.js"),workDir/"download/html5shiv.min.js")
  IO.copyFile(workDir/"download/html5shiv.min.js",staticDir/"js/html5shiv.min.js")
}
def downloadRespondMinJs(respondMinJsVersion: String,  workDir: File, staticDir: File) {
  IO.download(new URL(s"https://oss.maxcdn.com/respond/${respondMinJsVersion}/respond.min.js"),workDir/"download/respond.min.js")
  IO.copyFile(workDir/"download/respond.min.js",staticDir/"js/respond.min.js")
}
```

# WebJarsを使った場合
```build.sbt
libraryDependencies ++= Seq(
  "org.webjars" %% "webjars-play" % "2.5.0",
  "org.webjars" % "AdminLTE" % "2.3.8",
  "org.webjars" % "font-awesome" % "4.7.0",
  "org.webjars" % "ionicons" % "2.0.1",
  "org.webjars" % "html5shiv" % "3.7.3",
  "org.webjars" % "respond" % "1.4.2"
)
```

SBTだけでなく、Maven・Gradleなどのビルドツールでも使用可能です。
※詳しくはドキュメントを参照下さい


# 参考
[WebJars](http://www.webjars.org/)
[sbt.IO ドキュメント](http://www.scala-sbt.org/0.13/api/#sbt.IO$)
[Gradleの独自タスクで参考にさせて頂いたもの](http://ksby.hatenablog.com/entry/2016/09/19/012339)