Gradle/plugins

Eclipseプラグイン

gradleからEclipse IDEプロジェクトに必要なファイルを生成してくれる。 gradle eclipseと打つと、Eclipseプロジェクトに必要なリソースが生成され、プロジェクトインポートしてすぐにアプリケーション開発を始めることができる。

使い方

plugins {
    id 'eclipse'
}

または、

apply plugin: 'eclipse'

参考https://docs.gradle.org/current/dsl/org.gradle.api.Project.html

補足 pluginsとapply

applyでも可能であるが、pluginsの書き方の方が新しい。
pluginsは、プラグインのjarのロードとビルドプロジェクト内でのプラグイン実行(apply)の両方を行なう。
pluginsにapply falseを指定すると解決だけを行ない、プラグインの実行はapplyを使って別で行なうこともできる。プロジェクトでapplyを実行すると、Projectに対しプラグイン適応される。

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()
}

この状態で、gradle eclipseとしてもeclipseタスクは実行されない。

$ 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プロジェクト

Javaのプロジェクトを生成する場合は、Javaプラグインを有効にする。

plugins {
    id 'java'
    id 'eclipse'
}

または、

apply plugin: 'java'
apply plugin: 'eclipse'

プロジェクトの生成

Javaアプリケーションプロジェクトの生成

Javaアプリケーションの環境を作成する。

$ 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

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プロジェクトを生成する。

$ 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ファイルが生成されていることを確認できる。

参考リンク


トップ   差分 バックアップ リロード   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
目次
ダブルクリックで閉じるTOP | 閉じる
GO TO TOP