#author("2019-10-14T03:20:34+00:00","default:haikikyou","haikikyou")
#author("2019-10-14T03:32:33+00:00","default:haikikyou","haikikyou")
[[Gradle/plugins]]
#contents
* Eclipseプラグイン [#t259a3bb]
gradleからEclipse IDEプロジェクトに必要なファイルを生成してくれる。
gradle eclipseと打つと、Eclipseプロジェクトに必要なリソースが生成され、プロジェクトインポートしてすぐにアプリケーション開発を始めることができる。
* 使い方 [#rf6a2111]
#geshi(groovy){{{
plugins {
id 'eclipse'
}
}}}
または、
applyでも可能であるが、pluginsの書き方の方が新しい。pluginsは、プラグインのjarのロードとビルドプロジェクト内でのプラグインの適用を同時の行なう。pluginsにapply falseを指定するとjarの解決だけを行ない、適用はapplyを使って別で行なうこともできる。
#geshi(groovy){{{
apply plugin: 'eclipse'
}}}
&label(warn){参考};https://docs.gradle.org/current/dsl/org.gradle.api.Project.html
&label(info){補足}; ''pluginsとapply''
applyでも可能であるが、pluginsの書き方の方が新しい。~
pluginsは、プラグインのjarのロードとビルドプロジェクト内でのプラグイン実行(apply)の両方を行なう。~
pluginsに&code(){apply false};を指定すると解決だけを行ない、プラグインの実行は&code(){apply};を使って別で行なうこともできる。プロジェクトでapplyを実行すると、Projectに対しプラグイン適応される。
#geshi(groovy){{{
plugins {
// Apply the java plugin to add support for Java
id 'java'
// Apply the eclipse plugin, but not applying
id 'eclipse' apply false
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
}}}
この状態で、&code(){gradle eclipse};としてもeclipseタスクは実行されない。
#geshi(bash){{{
$ gradle eclipse
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/guest/workspace/gradle/eclipse/build.gradle' line: 15
* What went wrong:
Error resolving plugin [id: 'eclipse', apply: false]
> Plugin 'eclipse' is a core Gradle plugin, which is already on the classpath. Requesting it with the 'apply false' option is a no-op.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 597ms
}}}
** Javaプロジェクト [#zea2a49a]
Javaのプロジェクトを生成する場合は、Javaプラグインを有効にする。
#geshi(groovy){{{
plugins {
id 'java'
id 'eclipse'
}
}}}
または、
#geshi(groovy){{{
apply plugin: 'java'
apply plugin: 'eclipse'
}}}
* プロジェクトの生成 [#vcb73d6b]
** Javaアプリケーションプロジェクトの生成 [#s0544dfb]
Javaアプリケーションの環境を作成する。
#geshi(bash){{{
$ gradle init --type java-application --dsl groovy --test-framework junit --project-name myproj --package my
$ tree -a
$ tree -a
.
├── .gitignore
├── .gradle
│ ├── 5.6.2
│ │ ├── executionHistory
│ │ │ ├── executionHistory.bin
│ │ │ └── executionHistory.lock
│ │ ├── fileChanges
│ │ │ └── last-build.bin
│ │ ├── fileHashes
│ │ │ ├── fileHashes.bin
│ │ │ └── fileHashes.lock
│ │ └── gc.properties
│ └── buildOutputCleanup
│ ├── buildOutputCleanup.lock
│ ├── cache.properties
│ └── outputFiles.bin
├── build.gradle
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src
├── main
│ ├── java
│ │ └── my
│ │ └── App.java
│ └── resources
└── test
├── java
│ └── my
│ └── AppTest.java
└── resources
17 directories, 18 files
}}}
続いて、build.gradleを編集してeclipseプラグインを有効にする。
''build.gradle''
#geshi(groovy){{{
plugins {
// Apply the java plugin to add support for Java
id 'java'
// Apply the application plugin to add support for building a CLI application
id 'application'
// eclipseを追加
id 'eclipse'
}
...
}}}
Eclipseプロジェクトを生成する。
#geshi(bash){{{
$ gradle eclipse
BUILD SUCCESSFUL in 1s
3 actionable tasks: 3 executed
$ tree -a
.
├── .classpath
├── .gitignore
├── .gradle
│ ├── 5.6.2
│ │ ├── executionHistory
│ │ │ ├── executionHistory.bin
│ │ │ └── executionHistory.lock
│ │ ├── fileChanges
│ │ │ └── last-build.bin
│ │ ├── fileHashes
│ │ │ ├── fileHashes.bin
│ │ │ └── fileHashes.lock
│ │ ├── gc.properties
│ │ └── vcsMetadata-1
│ ├── buildOutputCleanup
│ │ ├── buildOutputCleanup.lock
│ │ ├── cache.properties
│ │ └── outputFiles.bin
│ └── vcs-1
│ └── gc.properties
├── .project
├── .settings
│ └── org.eclipse.jdt.core.prefs
├── build.gradle
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src
├── main
│ ├── java
│ │ └── my
│ │ └── App.java
│ └── resources
└── test
├── java
│ └── my
│ └── AppTest.java
└── resources
20 directories, 22 files
}}}
eclipseの.projectや.classpathファイルが生成されていることを確認できる。
* 参考リンク [#b3a3f0d9]
- https://docs.gradle.org/current/userguide/eclipse_plugin.html
- https://docs.gradle.org/current/userguide/plugins.html