Eclipse gradle integration - eclipse

Do eclipse project->build, project-build all, project->clean commands work with gradle projects? If they do, which gradle tasks do they invoke and where is console output.
Thank you!
--- Vadim

An eclipse project build/clean does normally use the integrated eclipse java compiler instead of gradle build system. So your build output is inside /bin folder. The eclipse internal build is very fast because of the eclipse delta compiler etc.
When you build your projects in gradle normally /build/** folders are used for gradle output results.
So you got "two worlds" / two output folders. This is important to understand when you are using console parallel with eclipse. Some gradle integrations for eclipse try to change this default behaviour and are adding special Builders to call gradle for build/clean etc. but - in my opinion - this will increase build time too much when your projects are growing bigger.
Instead of buildship you could also use EGradle IDE (https://marketplace.eclipse.org/content/egradle-ide).
Its lightweight, fast and compfortable. You can very simple call tasks in this eclipse integration for gradle. More information can be found at https://github.com/de-jcup/egradle/wiki/Help

Related

Use Gradle plugin without adding to build.gradle?

In Maven you can do mvn eclipse:eclipse to run the eclipse goal of the maven-eclipse-plugin. Is there a similar way to do this in Gradle? I'd like to run the plugin for my IDE of choice but I want my build script to remain "IDE-agnostic".
I don't want apply plugin 'eclipse' in my build.gradle file but want it to generate the Eclipse files it needs. This way users of IntelliJ won't need to swap it.
Rather than rely on the build tool to configure your IDE (who ever thought that was a good idea is beyond me), set up the IDE to understand and integrate with the build tool. Eclipse is specifically designed to share configuration in such a way that each person who checks out a project from source control gets the project configured correctly with a minimum of manual intervention. Gradle support is much newer and somewhat less mature than Ant or Maven, but it works. See the Buildship project, which allows you to point Eclipse at your existing Gradle-based project and import it as a properly configured Eclipse project, no need for hacks like mvn eclipse:eclipse (which is now deprecated/retired, by the way)

Is it possible for Gradle projects in Eclipse/STS to resolve dependencies to other Gradle projects in the same workspace?

A Gradle project in my workspace (call it Downstream) needs to depend on another Gradle project (call it Upstream). Outside of Eclipse, of course Upstream would need to be build and installed before Downstream (so that Gradle can resolve it). In Eclipse, since both projects are in the workspace together, I'd like to have Gradle look in the workspace first and make the dependency between the projects, not from the repo.
m2e (Maven integration for Eclipse) does this (the option is called Resolve dependencies from Workspace). Gradle Eclipse plugin has an option called Remap Jars to maven projects but that seems to do this for pom-driven m2e projects, not other Gradle projects.
Is there any way to get Gradle to resolve dependencies to the local workspace (when they're present) instead of the repo?
It turns out this is was an outstanding feature request for Gradle IDE. It has been delivered for the 3.6.3 release of Gradle IDE.
You do have to enable it, though:
The feature has to be enabled in the Gradle preferences page. Access
via "Window >> Preferences >> Gradle".
If you are not seeing the "remap jars to Gradle projects" there then
maybe double check that version of the Gradle plugins is indeed 3.6.3.
Maybe something went wrong during the upgrade and you are still using
an older version.
Source
As far as I know these is no such functionality in current STS plugin. Given that there is the re-mapping support to replace dependencies with reference to m2e project I think it should be possible to add it.
Modifying the generated classpath using XML hooks in EclipseClasspath model descrideb in http://www.gradle.org/docs/current/dsl/org.gradle.plugins.ide.eclipse.model.EclipseClasspath.html will probably not help because this is done in Gradle process where you do not have information about existing Eclipse projects from your current workspace.

Running Gradle inside Eclipse?

There appears to be an Eclipse plugin for Gradle, but no Gradle plugin for Eclipse...
Simply, I'd like to add a build.gradle to my Eclipse project, write its contents (including defining its dependencies), and then run it from inside Eclipse, the same way I can run Ant scripts from inside Eclipse.
When it runs, I'd expect the plugin to pull down all dependencies and make them available to my project's classpath in Eclipse.
If no such plugin exists, then I ask: what's the best way to develop in Eclipse, but keep your builds managed by Gradle? If I decide I need a new xyz.jar as a dependency for my code, how do I add it as a dependency in such a way that both Gradle and Eclipse will recognize it (and not throw compiler errors)?
Either use the IDE project generation approach (gradle eclipse), or use the Eclipse Gradle Integration. In both cases, you'll want to apply plugin: "eclipse".
The Gradle plugin for Eclipse is part of the Spring IDE. It understands the dependencies specified in the build script and makes those available in the .classpath.

In Eclipse for Java -JDT (DynWeb), Is Eclipse using default ant build.xml ? behind the scenes?

I believe when Eclipse installs, ant comes with it.
I should review the default build.xml
( I assume it uses one, whether or not it is obviously included in the project files )
I need to find out where it would store and use this from.
I have some projects / code artifacts that come with a build spec, and may need to use the one specified. Thanks in advance for your help, and suggestions.
Eclipse doesn't use ant to build your projects, if that's what you are asking. Eclipse builders (such as Java builder) are implemented natively as Eclipse plugins. Eclipse does support integration with Ant... Calling ant targets as part of the build... Calling ant targets as separate tools... Ant is meant to be used to augment IDE-provided facilities when you need something specialized.

synchronising / maintaining ant and eclipse classpaths

I'd be interested to find out about any automated processes that people have for ensuring that the project classpaths for the ant and eclipse configurations are in synch. In my case, I want the classpath defined in the ant build file to be the master configuration, since its used for our production builds. As part of the build i'd like to add an ant target that will verify that the eclipse classpath is up to date, or at least indicate differences between the two classpaths.
I'm aware of ant4eclipse but its focus is in the opposite direction, ensuring that the eclipse classpath is master and that the ant build reuses the eclipse path. I like the idea behind AntAndEclipse but am wondering are their ant other tools in this space that i'm not aware of.
You solution at a previous company was to have ant invoke Eclipse to do the compiles as described here:
http://www.eclipse.org/articles/Article-PDE-Automation/automation.html
I'm not aware of any ant tools which can do this but I've switched from ant to Maven a few years ago and never looked back. You can use the "Maven integration for Eclipse" to make Eclipse use the Maven classpath.
As of today, I'm not 100% happy with the Eclipse plugin, though. It's a bit slow and due to the different philosophy of Eclipse and Maven, some operations behave strange. For example, Eclipse doesn't differentiate between a "production" and "test" classpath, so you can get compile errors in Maven when everything looks great in Eclipse.
My solution was to use the plugin to keep the classpath in sync and compile from the commandline.
there is an ant task to do xml transformations, we used that task to create the classpath in our build file. It was a little trick to get the XSL right but once it worked it was great
Did you evaluate Apache IVY? Currently I am building a Continuous Integration environment at our place and we use IVY to handle our dependencies. There is a eclipse plugin that takes the dependency configuration of eclipse and uses it as eclipse classpath.
Currently this solution looks quite promising.
My team wrote an Eclipse plug-in to add a new type of library to the Java Build Path->Add Library option in the project settings. This custom library type allowed both Eclipse and ANT to reference the same canonical list of dependencies.
Nowadays, I'd probably look at IVY for doing the same thing if I was locked into using ANT, rather than writing my own.
You need Ant2Eclipse.