今天下载了Oxygen来使用,不知道这个版本对Gradle的支持是不是好一点了,以前的版本虽然可以用Gradle,但是集成度和Marven比还差不少,于是搜索了一下,找到一篇文章讲到了这个内容,看上去是有进步了,先转载一下。(http://www.vogella.com/tutorials/EclipseGradle/article.html)
Gradle Inc., the company behind the Gradle build framework provides Gradle tooling for the Eclipse IDE. This tooling allows to create and import Gradle enabled projects into the Eclipse IDE. It also allows to run Gradle tasks and monitor it execution.
The Eclipse project itself is called Buildship. It is available on Buildship on Github.
The easiest way to install the Eclipse Gradle tooling is by using the Marketplace client. Search for Buildship.
You also can use the Help ▸ Install New Software menu path to install the Gradle tooling.
For example, the following URLs are available for the different Eclipse releases:
Eclipse 4.7 Neon release
Eclipse 4.8 Oxygen release
The Eclipse Gradle project provides also other updates sites, e.g., for developer builds. See the Buildship download page for details: https://projects.eclipse.org/projects/tools.buildship/downloads
The Eclipse Gradle tooling provides a wizard for the creation of Java based Gradle projects. You can reach it via the File ▸ New ▸ Other… menu entry.
Click on the Next > button.
Press the Finish button to create the project. This triggers the gradle init --type java-librarycommand and imports the project. Press the Next > button to get a preview of the configuration before the projects created.
The created project looks similar to the following screenshot.
The following demonstrates how to create a Spring Boot webapplication with Gradle.
First, create a standard Gradle project called com.vogella.springboot.gradle.minimal.
Change the build.gradle file to the following:
buildscript { ext { springBootVersion = '1.5.3.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } }
apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot'
jar { baseName = 'com.vogella.springboot' version = '0.0.1-SNAPSHOT' }
sourceCompatibility = 1.8
repositories { mavenCentral() }
dependencies { compile('org.springframework.boot:spring-boot-starter') compile('org.springframework.boot:spring-boot-starter-cache') compile('org.springframework.boot:spring-boot-starter-data-rest') compile('org.springframework.boot:spring-boot-starter-hateoas') compile('org.springframework.boot:spring-boot-starter-data-jpa') compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('com.h2database:h2') testCompile('org.springframework.boot:spring-boot-starter-test') testCompile('org.springframework.restdocs:spring-restdocs-mockmvc') }Create the following class.
package com.vogella.springboot.gradle.minimal;
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication public class Application {
public static void main(String[] args) { SpringApplication.run(Application.class, args); }}
Select this class, and select via the context mene Run-As ▸ Java Application.
This starts String Boot and the selected application on http://localhost:8080.
To learn more about Spring Boot, see the Spring tutorial.
You can also import existing Gradle projects into Eclipse. Select the File ▸ Import… ▸ Gradle ▸ Gradle Project menu entry for this.
After pressing the Next > button, you need to specify the root directory of your Gradle project.
You may now press Finish button and use the default settings for the import or press the Next button and specify the Gradle runtime settings.
Afterwards the import preview is shown.
Eclipse does not automatically update the classpath, if the build.gradle file is updated. Select Gradle ▸ Refresh Gradle Project from the context menu of the project or from your build.gradle file for that.
To convert a Java project to use Gradle, select Gradle ▸ Add Gradle Nature from the context menu of the project.
Run the 'gradle init' task to create the initial Gradle files, in case you do not have them yet.
The Gradle Tasks view shows the available Gradle tasks for your projects.
Via the context menu you can run a selected Gradle task.
By default, the result is displayed in the Gradle Executions view. It is also displayed in the Console view. This is similar to the output you would get if you run the task via the command line.
The Gradle Executions view can only be used, if you use Gradle 2.4 or higher.
To compile Android projects with the Eclipse IDE, you can use gradle-android-eclipse plug-in from https://plugins.gradle.org/plugin/com.greensopinion.gradle-android-eclipse. Afterwards the Android project should complile in the Eclipse IDE and you can run the Gradle tasks via the Gradle Task view.
After you installed the Buildship tooling, you can help the project by reporting issues in the Gradle Forum or by contributing code.
To help the Buildship project, please report all issues with the tooling via: New Bug report for Buildship You can report bugs or feature requests.
Since the project is hosted on Github, you can obtain the source by cloning it from the following URL:
git@github.com:eclipse/buildship.git
The project also provides a Oomph setup for the development, which is explained further in the Buildship Docs.
GitHub repository for the Gradle Eclipse tooling
Gradle Eclipse (Buildship) project site on eclipse.org
Slides of the Eclipse Buildship Talk at a Java User Group meetup in Hamburg 2015
buildship-dev mailing list
The vogella company provides comprehensive training and education services from experts in the areas of Eclipse RCP, Android, Git, Java, Gradle and Spring. We offer both public and inhouse training. Whichever course you decide to take, you are guaranteed to experience what many before you refer to as “The best IT class I have ever attended”.
The vogella company offers expert consulting services, development support and coaching. Our customers range from Fortune 100 corporations to individual developers.
Copyright © 2012-2017 vogella GmbH. Free use of the software examples is granted under the terms of the EPL License. This tutorial is published under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Germany license.
See Licence.