We\'re looking at converting our Ant build to Gradle.
In regards to integration with Eclipse, we are looking for (conceptually) equivalent functionality for launch
You can use the Gradle Eclipse plugin like gradle eclipse
to generate an Eclipse project from the gradle project. It adds a lot of targets to the generated Eclipse projects and is highly customizable.
I know this is an old question, but I still do not think it is possible to have Eclipse run a gradle build for you. The Spring Gradle plugin is a great start, if you use that, you can define an external tool builder to run gradle when you want. If you have lots of projects and all are being built with gradle, you can even have gradle add the capability to your eclipse projects for you. While this can be cleaned up, you can add something like this to your gradle build file:
apply plugin: 'eclipse'
eclipse {
project {
// Store a copy of the desired Gradle_Builder.launch file in a top-level 'master'
// directory. Then this code searches for it, and by copying it,
// adds the launch file to the specifc project that will run gradle
String launchFileNameOrig = '.externalToolBuilders/Gradle_Builder.launch'
String launchFileName = launchFileNameOrig
File launchFile = file(launchFileName)
boolean needToCopy = false
while (!launchFile.exists()) {
launchFileName = '../' + launchFileName
launchFile = file(launchFileName)
needToCopy = true
}
if (needToCopy) {
copy {
from (launchFile)
into '.externalToolBuilders'
}
}
buildCommand 'org.eclipse.ui.externaltools.ExternalToolBuilder', LaunchConfigHandle: '<project>/'+launchFileNameOrig
file {
// when they made the "buildCommand" it looks like they left off 'triggers', so parse the XML until
// the right place is found, then insert it.
withXml {
def projectNode = it.asNode()
projectNode.iterator().each { subNode ->
String subNodeText = '' + subNode
if (subNodeText.startsWith('buildSpec')) {
subNode.iterator().each { buildCmd ->
String nameNode = buildCmd?.name
if (nameNode.contains('ExternalToolBuilder')) {
buildCmd.appendNode('triggers', 'full')
}
}
}
}
}
}
}
This is the content of the file stored at the top of the directory hierarchy under: ./.externalToolBuilders/Gradle_Builder.launch. As defined here, this will only run after a "clean" [Gradle is more expensive time-wise than the native Java Builder, so continue to use that for auto-building]. Note: the file contents below also assumes that you are using "git" and the gradle wrapper. You see this on the ATTR_LOCATION value. Adjust as needed. One nice thing about this approach though is that you can have the gradle wrapper be any version of gradle you want, and then eclipse will use that version when it runs!
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType">
<stringAttribute key="org.eclipse.debug.core.ATTR_REFRESH_SCOPE" value="${workspace}"/>
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${git_dir}/../gradlew"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="assemble"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${project_loc}"/>
</launchConfiguration>
I came across this question after installing the newer Buildship plugin which is phasing out Spring Tool Suite mentioned by others here.
Instructions for using task view with Buildship are as follows:
Using the Gradle Tasks view
After successfully importing a Gradle project, the project is shown in the Gradle Tasks view. By right clicking on a certain Gradle task in the Gradle Tasks view, you can run the selected Gradle task.
By default the result is displayed in the Gradle Executions view. It is also displayed in the Console view similar to the output you would get if you run the task via the command line.
Source
The current answer to this question should be, Use Gradle's own Eclipse plugin Buildship:
http://projects.eclipse.org/projects/tools.buildship
This is supported and developed by the Gradle team and will be continuously improved in the future. It can also handle older versions (with functionality based on Gradle version availability).
Edit 2017-03-01: After the release of Buildship 2.0, the integration is even better and I recommend it (unless your already using IntelliJ, then your already set). There are still some features missing like the ability to directly debug JavaExec tasks and the ability to run precompile/preimport tasks, but those are in their Github issues list.
As ever, you are better off with IDEA. Support has been around since 2009 http://blogs.jetbrains.com/idea/2009/08/gradle-support/
and even fuller support is available now via the EAP (free to use!) http://blogs.jetbrains.com/idea/2011/09/keen-to-try-gradle-integration-in-intellij-idea/
The short answer is that we do not invoke gradle scripts from Eclipse.
I believe this site outlines where this work is at the moment and it does not seem to be much right now.
I am a bit curious what kind of tasks you want to run from Eclipse. Why not run tasks from the command line?