LoginSignup
3
2

More than 5 years have passed since last update.

SpringBoot+Gradleでgrunt/bowerをする

Posted at

やること

  • gradle buildした時にgrunt/bowerしてくれたら素敵じゃないかと。
  • SpringBoot+Gradleでサーバサイドを構築
  • クライアントサイドはstaticに配置
  • gruntやbowerをgradle build時に実行させる
    • git clone -> gradle buildでjar作成まで自動化

Gradleの設定

  • Gradleからnodeやgruntを使いたいのでpluginを入れる
  • nodeとgruntに作業ディレクトリ等の設定をする
  • classesゴールの前にgrunt buildやnpm installを実行させる
    • node_modules、bower_componentsフォルダはひとまずプロジェクトルートに置く
build.gradle

buildscript {
    repositories {
      mavenCentral()
      maven {
        url "https://plugins.gradle.org/m2/"
      }
    }
    dependencies {

______

      // for grunt/bower
      classpath "com.moowork.gradle:gradle-node-plugin:0.11"
      classpath "com.moowork.gradle:gradle-grunt-plugin:0.11"
    }
}

______
apply plugin: "com.moowork.node"
apply plugin: "com.moowork.grunt"
______

node {
  version = '0.12.7'
  download = true
  workDir = file("${project.buildDir}/nodejs")
  nodeModulesDir = file("${project.projectDir}")
}

grunt {
  // Set the directory where Gruntfile.js should be found
  workDir = file("${project.projectDir}")
}

// npm install -> installGrunt -> grunt buildをclassesの前に割り込み

classes.dependsOn grunt_build
grunt_build.dependsOn npm_install
grunt_build.dependsOn 'installGrunt'


npm installしたら自動的にbower installさせる

  • 上記設定だとbower installが入っていない
    • bower installをgradleで実行するプラグインもあるようだが未検証
  • bower installはnpm installと一緒に実行されるようにpackage.jsonに記載する
package.json

___略___

  "scripts": {
    "postinstall": "bower install"
  },

___略___

grunt/bowerに必要な情報を配置

  • projectルート直下に以下を配置
    • package.json
    • bower.json
    • Gruntfile.js

実行

  • gradle buildするとnpm installやbower install、grunt buildが実行される

まとめ

  • わりと簡単にgradleからgrunt/bowerすることができた
  • あとはjenkinsおじさんを使えば自動デプロイまでもっていけそう
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2