2
3

More than 5 years have passed since last update.

[Grails] プラグインの基本的な使い方

Last updated at Posted at 2013-10-25

資料

本家ドキュメントはhttp://grails.org/doc/latest/guide/conf.html#dependencyResolution
日本語ドキュメントはhttp://grails.jp/doc/latest/guide/conf.html#dependencyResolution

インストール方法

grails-app/conf/BuildConfig.groovy 内の plugins に欲しいプラグインを追記します。
今回は、Spring Security Core Pluginの2013年10月23日時点で最新のものをインストールしました。

grails-app/conf/BuildConfig.groovy
plugins {
    ...
    compile ":spring-security-core:2.0-RC2"    // 追記
}

これで grailsコマンドでインタラクティブモードを起動すれば必要な物のダウンロード、クラスパスの設定など全て自動で行われます。

Grailsの公式で配布されているプラグインは以下から検索できます。
どういった形式で plugins に追記すれば良いのかも書かれていてとても親切です。
http://grails.org/plugins/?filter=all

以下のコマンドでもプラグインのインストールが出来ますが、少なくともGrails2.2.3の時点では、 既に非推奨 となっています。

grails install-plugin spring-security-core

アンインストール方法

プラグインのアンインストールは、以下の手順を踏みます。

  1. BuildConfig.groovyのアンインストールしたいプラグインの記述をコメントアウトか削除。
  2. コマンド grails uninstall plugin [プラグイン名]を実行。

注意点としては、Grailsのインタラクティブモードではプラグインのアンインストールは出来ないという点です。

grails-app/conf/BuildConfig.groovy
plugins {
    ...
    //compile ":spring-security-core:2.0-RC2"
}
grails> uninstall-plugin spring-security-core
| Error You cannot uninstall a plugin in interactive mode.
grails> exit
| Goodbye
[c:grailssamples]
$ grails uninstall-plugin spring-security-core
| Uninstalled plugin [spring-security-core]

エラー発生!

今回 compile ":spring-security-core:2.0-RC2"plugins に指定した際に下記のエラーが表示されました。

| Error Failed to resolve dependencies (Set log level to 'warn' in BuildConfig.groovy for more information):

- org.springframework.security:spring-security-core:3.2.0.RC1
- org.springframework.security:spring-security-web:3.2.0.RC1

これは単純に

  • org.springframework.security:spring-security-core:3.2.0.RC1
  • org.springframework.security:spring-security-web:3.2.0.RC1

の2つがリポジトリから見つけられないよ、という意味です。
そこで、Spring Security Core PluginCustom repositories にあるとおり、mavenRepo "http://repo.spring.io/milestone/"BuildConfig.groovyrepositories に追記します。

grails-app/conf/BuildConfig.groovy
repositories {
    ...
    mavenRepo 'http://repo.spring.io/milestone'
}

で、再度 grailsコマンドでインタラクティブモードを起動すると、今度はちゃんと最後まで実行されました。

こんな感じでログが流れます。

| Loading Grails 2.2.3
| Configuring classpath
| Downloading: spring-security-core-3.2.0.RC1.pom
| Downloading: spring-security-core-3.2.0.RC1.pom.sha1
| Downloading: spring-security-web-3.2.0.RC1.pom
| Downloading: spring-security-web-3.2.0.RC1.pom.sha1
| Downloading: spring-security-core-3.2.0.RC1.jar
| Downloading: spring-security-core-3.2.0.RC1.jar.sha1
| Downloading: spring-security-web-3.2.0.RC1.jar
| Downloading: spring-security-web-3.2.0.RC1.jar.sha1
| Downloading: spring-security-web-3.2.0.RC1.jar.sha1.
| Environment set to development
| Environment set to development.
| Environment set to development..
| Environment set to development...
| Environment set to development....
| Environment set to development.....

プラグインの一覧

以下のコマンドで、Grailsの公式リポジトリで公開中のプラグインの一覧と、インストール済みのプラグインの一覧が表示できます。

grails list-plugin

実行結果は以下

grails> list-plugin
| Environment set to development.....

Plugins available in the grailsCentral repository are listed below:
-------------------------------------------------------------
DjangoTemplates Plugin<>               --
None                <>               --
acegi               <0.5.3.2>        --  Acegi Plugin
activemq            <0.4.1>          --  Grails ActiveMQ Plugin

... すごく長いので省略 ...

zoo-keeper          <0.1>            --  Grails ZooKeeper Helper


Plug-ins you currently have installed are listed below:
-------------------------------------------------------------
cache               1.0.1            --  Cache Plugin
database-migration  1.3.2            --  Grails Database Migration Plugin
hibernate           2.2.3            --  Hibernate for Grails
jquery              1.8.3            --  JQuery for Grails
resources           1.2              --  Resources
tomcat              2.2.3            --  Apache Tomcat plugin for Grails
webxml              1.4.1            --  WebXmlConfig

最後に表示されるインストール済みプラグインの一覧は、アンインストールしたプラグインも表示されてしまうことがあります。
run-appでアプリケーションを起動すると、ちゃんと上記のインストール済みプラグインの一覧から消えることを確認しました。

その他

プラグインのインストールには、grialsコマンドを実行する必要がありますが、開発環境でIntelliJを使っている場合は、 Buildconfig.groovy を編集した時点でエディタ上部に Apply Grails changes to IDEA project structureというリンクが出てくるので、それをクリックすれば同じようにプラグインがダウンロード、設定されます。

2
3
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
2
3