How to make Android Studio and Eclipse coexist (gradle dependencies) - eclipse

I need to use Eclipse and Android Studio on the same computer, simultaneously, for different projects.
The Eclipse project is Enterprise Java deploying on Payara (Glassfish) via the WTP toolkit and Deployment Assembly. When setting up the project I build with gradle build and gradle eclipse, which pulls all the required dependencies and configures the Deployment Assembly in Eclipse. However, I believe that any incremental code changes thereafter are compiled by Eclipse without using gradle (e.g., when I save a file).
Android Studio always compiles with gradle.
The issue that I have is that every couple of weeks, when I compile my Android Studio project, gradle decides to delete all my Eclipse project dependencies. My guess is that it thinks that they are not in use any more, since Eclipse compiles outside gradle. This results in my Eclipse workspace pointing to libs that are no longer there.
If I manually run gradle build in my Eclipse project dir, my dependencies are restored and Eclipse no longer complains. But something seems to be cached wrong somewhere so after this my web app will no longer deploy on the server. At that point my workspace is effectively corrupted and to this day I haven't found any workaround, other than to delete it and start all over again. Which is *A LOT* of work to reconfigure.
Any help will be greatly appreciated.

Related

Buildship and Eclipse project dependencies

We are using eclipse and a buildserver activly. We switched to gradle on the buildsystem first. Therefore we wrote for each eclipse project a gradle file. Using a artefact repository to which it is published, everything worked fine.
Now we are switching our IDEs to buildship. Building a single project works fine. However how can I reference in the build.gradle another eclipse project, without building it first on the buildsystem?
Thanks

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.

Debugging a Gradle 1.12 dependency resolution issue

I am using Gradle 1.12 to build an Android library. The build script works fine and the artifacts are installed to both a Maven local repository and deployed (using an S3 wagon Gradle plugin) to a remote Maven repository. When these artifacts are referenced by a Gradle (1.12) build of a sample app using the Maven local repo, all works fine. When the remote repository is used, a Gradle dependency resolution error is reported [details on the error will be provided later].
To get more information about the problem in order to fix my script or file a bug report, I would like to do some debugging of Gradle 1.12 while the sample app build script runs. Eclipse would seem to have the debugger of choice but configuring Eclipse is the subject of this post.
Following advice on the Gradle forums, it is straightforward to configure Gradle startup options to suspend on startup and await a connection from a client debugger (Eclipse).
Configuring Eclipse to do this is proving difficult. At first glance, it would seem that one needs a Gradle plugin. Spring Source provides a recommended one. But this plugin appears to bury and use Gradle 1.10. Perhaps upgrading this plugin to use 1.12 is easy and an answer that details how to do this would be a great answer.
The critical pieces of the answer I am looking for will enable me to place breakpoints in Gradle classes and step through source code until I either find a bug or figure out what I might be doing incorrectly in my build script.
Alternative approaches, such as using Intellij or Android Studio would be good answers as well if accompanied by details and/or references that make it clear how to enable the Gradle debugging process.
Debugging Gradle works exactly the same as (remotely) debugging any other Java application. No Gradle plugin is needed for this. In a nutshell, you need to start a remote debugging session from an Eclipse project that has Gradle sources. One way to create such a project is to clone the Gradle GitHub repository and run gradlew eclipse.

Eclipse dependent projects not copied to WTP deployment

Before we started using Gradle, a multi-project (10-12) development effort within Eclipse successfully deployed, via a WTP project, to one of the internal Tomcat 7 servers. We find this very useful for development.
With Gradle up and running the dependent project's jar files are no longer being copied to the ../WEB-INF/lib directory. I don't believe this has anything to do with gradle as it is completely out of the picture later on, but it is different, so I am mentioning it. Building the standalone war file works perfectly as does "gradle jettyRun".
If I add the project facet "Utility Module" to the dependent projects within Eclipse then it works. However, I don't recall that this was ever done initially. Ok, this also really complicates the generation of the eclipse projects from gradle as well!
I can live with it, but was wondering if anyone knew if it has to be this way or if there is some alternative.
Thanks - versions: eclipse Indigo SR2, Java 1.7, Gradle 1.2
I've run into this problem as well: An Eclipse WTP project that depends on other projects won't deploy those projects' dependencies unless they are WTP projects as well.
This is far from an ideal solution, but in my own build scripts, I work around this by using the eclipse-wtp plugin instead of the eclipse plugin:
allprojects {
apply plugin: 'eclipse-wtp'
}
There are a couple of bugs related to this: GRADLE-1880 and STS-2192.

Gaelyk eclipse configuration error

I've tried to configure a gaelyk project in eclipse using the gradle script of the template project and always failed.
to do this I use the following command:
gradlew cleanEclipse eclipse
All the packeges seems correctly downloaded, the .project and .classpath files are created but I always fint this error on the project:
The App Engine SDK 'C:\Users\username\.gradle\caches\artifacts\com.google.appengine\appengine-api-1.0-sdk\c12498cf18507aa6433a94eb7d3e77d5\jars\appengine-api-1.0-sdk-1.6.1.jar' on the project's build path is not valid
(SDK location 'C:\Users\username\.gradle\caches\artifacts\com.google.appengine\appengine-api-1.0-sdk\c12498cf18507aa6433a94eb7d3e77d5\jars\appengine-api-1.0-sdk-1.6.1.jar' is not a directory)
It seems that the appengine SDK is specified uncorrectly in the .classpath/.project files.
I've installed eclipse Indigo and the last version of the google plugin for eclipse
How can I fix it?
I am personally not using Eclipse for Gaelyk development. Therefore, I am not sure if the existing Eclipse configuration in the Gradle build script of the template project will work with the Google plugin.
However, a while ago I got a pull request for the Gradle GAE plugin to integrate with the Eclipse plugin. I had turned it down because it's too specific and it would lead to potentially a lot of bugs to the Gradle plugin as the Google configuration might change. The author was planning to creating a separate plugin for it so you can try to ping him.
I also know of another Gradle plugin that might help you here. Also try to post your question the Gaelyk mailing list.