Gradle Eclipse Plugin only half-working - eclipse

I am trying to achieve the following between Eclipse and Gradle:
Allow Gradle to handle 100% of my local build logic; only use Eclipse as an IDE for syntax highlighting, refactoring, etc. Every time I wish to build my app I want to drop into a command line and run a Gradle build invocation from there.
I want the dependencies closure of my build.gradle file to be the sole location for configuring 3rd party dependencies; every time I make a change to this closure (adding/removing a dependency/JAR), I want Eclipse to automagically "see" this change and adjust my project's classpath accordingly
I installed the Gradle-Eclipse Integration plugin and then I followed this tutorial for configuring it correctly.
First I ran:
gradle clean build
And then I added:
apply plugin: 'eclipse'
To my build.gradle, and then ran:
gradle eclipse
I saw a lot of output, the tail end of which is:
gradle eclipse
:myapp:eclipseClasspath
Download http://repo1.maven.org/maven2/org/apache/commons/commons-lang3/3.3.2/commons-lang3-3.3.2-sources.jar
Download http://repo1.maven.org/maven2/org/sonatype/sisu/inject/cglib/2.2.1-v20090111/cglib-2.2.1-v20090111-sources.jar
Download http://repo1.maven.org/maven2/asm/asm/3.1/asm-3.1-sources.jar
Download http://repo1.maven.org/maven2/com/google/inject/guice/3.0/guice-3.0-sources.jar
Download http://repo1.maven.org/maven2/org/codehaus/groovy/groovy-all/2.3.7/groovy-all-2.3.7-sources.jar
Download http://repo1.maven.org/maven2/aopalliance/aopalliance/1.0/aopalliance-1.0-sources.jar
Download http://repo1.maven.org/maven2/javax/inject/javax.inject/1/javax.inject-1-sources.jar
:myapp:eclipseJdt
:myapp:eclipseProject
:myapp:eclipse
I then opened my .classpath file and see that its been correctly updated with all the transitive dependencies defined in my dependencies closure back inside build.gradle.
However, there is not visual indication inside Eclipse that anything is wired correctly. With Ivy or Maven, you usally get something like a Ivy Repository Manager or Maven Dependency Library that automatically changes anytime you modify ivy.xml or pom.xml.
Most importantly, this just doesn't seem to be working! As you see above, Apache Commons Lang 3 is a dependency, but when I try to add org.apache.commons.lang3.exception.ExceptionUtils to a Groovy source file, Eclipse can't find it. I have already tried restarting Eclipse to see if that shook any bugs out.
Am I just not using this plugin correctly, or does it just not work? Using Groovy/Grails Tool Suite 3.6.0.RELEASE here, which is based on Eclipse Luna 4.4.

Related

Project not built. Build path incomplete. Repairing build path did not work

java version "10.0.1"
Eclipse jee 2018-2019
Windows 10
I'm just trying to add a simple file to my package. After adding the file, I get the below error.
The project was not built since its build path is incomplete. Cannot
find the class file for groovy.lang.GroovyObject. Fix the build path
then try building this project.
Pretty much all posts say to delete the JRE System Library and add it again, do a refresh, clean restart. I did this, but I'm still getting a build path error.
I followed these instructions. Other forums on stack say similar things.
http://hemant-vikram.blogspot.com/2012/07/eclipse-build-error-project-was-not_12.html
New to Eclipse and Groovy. I just want to follow the tutorial :|
If you have added references to Groovy types, you can add Groovy libraries to your classpath by right-clicking on your project and choosing "Add Groovy Libraries to classpath". This assumes you have Groovy Development Tools installed.
Or you can add "org.codehaus.groovy:groovy-all" through Ivy, Maven or Gradle if you are using one of those for dependency management.

How do I refresh project dependencies using Buildship in Eclipse?

Eclipse Mars was recently released and I felt like trying it out. It listed tighter integration with Gradle as one of its features via Buildship.
With Luna I was using Gradle Integration for Eclipse (4.4) and I found this a lot easier to work with for what I was trying to do; I could add a Gradle "nature" to an existing project without needing to remove the project and re-import it as I did with Buildship, and it automatically put all dependencies that I declared in build.gradle within the project's classpath.
With Buildship, I didn't see any option to configure an existing project as a Gradle project and I couldn't find a way to make it include the dependencies I specified in the build script within the project's classpath.
I tried installing the original plugin (GIfE 4.4) for Eclipse Mars and after restarting Eclipse it automatically did all that for me again. What I'm wondering is if there's a way to do this all through Buildship alone because right now, although it all works, it's quite a funny setup. My project's dropdown menu looks like this:
Apart from looking a bit odd it is actually quite a nice setup, since it combines the automatic dependency management of GIfE with the ability to run Gradle tasks directly from Eclipse that Buildship provides.
Updating the dependencies that eclipse sees should then be as simple as:
right click on project -> gradle -> refresh all
Update in buildship 1.0.16
Currently you need to jump through the delete-and-import hoop the first time you use an existing gradle project with buildship. You can now use the Add Gradle Nature option:
right click on project -> configure -> Add Gradle Nature
“Refresh Gradle Project” is now also shown when right-clicking on any .gradle file as well as in the context menu of the Gradle editor. source
See update below However sometimes you may find that when your project was imported, it didn't get the new Project and External Dependencies classpath entry which you would normally be able to see in your Project Properties -> Java Build Path -> Libraries
If this is indeed missing, add the following to your project's .classpath file and all the gradle goodness should start working:
<classpathentry exported="true" kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
Update in buildship 1.0.16
Gradle classpath container is restored if missing
When converting an existing Eclipse Java project to Gradle, the Gradle classpath container was missing. It is now always added when a project is a Java project.
Incase for anyone, if you are not getting the
right click on project -> gradle
link after doing the steps mentioned in #PaulAdamson answer. Try this.
In your build.gradle add apply plugin 'eclipse';
Close the project in eclispe.
Run the gradle build from command line and then reopen the project in eclipse.
Now the gradle link should be available on right click.
I agree Buildship is a bit of a disaster. The documentation is extremely sparse with limited examples and minimal user guide. You would think documenting the transition from Gradle Integration for Eclipse (4.4) would be a no-brainer but I guess not. I also don't have a single clue how to use Buildship other than that I ran some tasks manually and it put fully qualified paths in my .classpath file. That's ridiculous considering many projects are shared through change control systems.
Currently there is no "Convert to Gradle project" implemented in Buildship. However, if you remove the project and reimport it using the Gradle import wizard you should see the same exact project with the proper nature and the classpath container.
On top of that, if you have a Gradle project in your workspace and update the dependencies in the build script, you can refresh the classpath container by right-clicking on the project and select Gradle > Refresh projects.
A similar problem you were facing was discussed in the Gradle forums: discuss.gradle.org/t/adding-dependencies-to-projects/10415.
We also have a bug dedicated for this feature request: bugs.eclipse.org/bugs/show_bug.cgi?id=465355. Please vote for it and share your thoughts there too.
Regarding to the documentation: It's true that we haven't provided an official documentation for the central Eclipse help system, but there are some resources explaining the current functionality:
The user documentation on GitHub
A Vogella tutorial
If you have already converted Java project to Gradle project but [RIGHT-CLICK]+Import (Then importing 'Existing Gradle Project') then your project should be of Gradle Nature.
If the project is of Gradle Nature then in .classpath file you will not see all the .jar dependencies as you see in normal java project, Instead you will see a single entry of:
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
To refresh dependencies you should do following:
[RIGHT-CLICK] + Gradle + Refresh Gradle Project
This will fix all complication issues.

How to import playframework sources into eclipse?

After cloning playframework from github and importing java sources into eclipse there are a lot of build errors shown.
Running the goals from ant file in eclipse works fine as well as building from cli directly.
How can i resolve these errors in eclipse?
I took the following steps to import play into eclipse:
new -> other -> Java>New Java Project from Existing Ant Buildfile
select play/framework/build.xml
checking the 'Link to the build file in the file system' checkbox
Finish
The errors result from differences between eclipse internal build path
and classpath available for ant at runtime.
First Eclipse only imports rt.jar from system path. This may lead to
missing dependecies in javax.net packages (e.g.
javax.net.ssl.SSLException), which is located in jsse.jar. To fix, right
click on project->Properties->Java Build Path->Libraries->Add Library->
JRE System Library.
Second, play has dependencies to classes from ant runtime. To fix, right
click on project->Properties->Java Build Path->Libraries->Add
Library->User Library
There you have to add a new User Library (perhaps call it ANT) and add
all ant-jars from your ant installation (/usr/share/ant/lib/ worked for
me). Then add this user library to play projects build path.
From the Oliver's answer, I had also to add the jce.jar lib in my classpath.
It comes from the $JDK/jre/lib directory.

gwt-maven-plugin with Eclipse Indigo

I would just like to setup a new GWT project in Eclipse and use Maven for dealing with all the jar jungle. I used gwt-maven-plugin with this instructions, but I can't get the project to work in Eclipse.
What I've actually done:
Created a maven project using the archetype gwt in command line.
Imported the projet in eclipse using import > existing maven project
While doing that I had errors saying:
gwt-maven-plugin:2.3.0-1:generateAsync - "No marketplace entries found to handle"
gwt-maven-plugin:2.3.0-1:i18n - "No marketplace entries found to handle"
gwt-maven-plugin:2.3.0-1:exploded - "No marketplace entries found to handle"
These errors don't go away even if I ignore them on the import.
How can I make these projects working? Is the problem that I skipped the "process-resources" setting? (There is no such setting in the latest version of m2e.)
Should I even use gwt-maven-plugin? Is there any other way of making a GWT project to use Maven? Or – is there any other way to fight with the jar jungle? What does GWT guys use?
I use Eclipse Indigo with m2e plugin 1.0.0 and Google suite plugin version 2.3.3.
Eventually I gave up Maven. As one other developer said "good ideas and bad code build communities faster" , I also remember my experience with Maven on all the projects: very promising on the beginning, but eventually you get to some problems and end up working more with configuring Maven than actually dealing with your own code.
I decided to manually copy needed .jar-s into /lib folder. I spent some time due to transitive dependencies, but LESS than dealing with Maven and now I have things under control. If sometime in the future working with libraries will become an overhead, I will consider using Ivy.
If someone wishes to stick with Maven, I lately found a very useful link by Google team:
http://code.google.com/p/google-web-toolkit/wiki/WorkingWithMaven
They recommend using their sample projects and not gwt-maven-plugin archetypes (due to issues). I agree. They also provide needed pom lifecycle changes for Eclipse Indigo.
According to a recent post on the gwt-maven-plugin mailing list the Maven integration is not complete for Eclipse Indigo, since the M2Eclipse 1.0 release has brought about a large number of changes. The suggested workarounds from David Chandler, Google engineer, are:
You can run "mvn package" on the command line or right-click on the project > Maven > Run as > Maven build.
The plugin execution failures you're seeing can be resolved by adding lifecycle mapping metadata as in the sample POMs. They are only needed for Indigo. You should not get these errors in Helios or when running mvn package from the command line.
Disclaimer: The following guidelines are for Windows users. These steps are on the basis that, they have worked when tried by the replier and doesn't guarantee fulfledge working unless experimented by self and tried with proper prerequisites.
::Creating a simple gwt project using archetype::
Following are few commands that can be used to create a simple gwt project "Web Starter Application":
mvn archetype:generate -DarchetypeGroupId=org.codehaus.mojo
-DarchetypeArtifactId=gwt-maven-plugin -DarchetypeVersion=2.3.0
mvn -DarchetypeGroupId=org.codehaus.mojo
-DarchetypeArtifactId=gwt-maven-plugin -DarchetypeVersion=2.3.0 -DgroupId={project packaging} -DartifactId={application name} -Dversion=1.0 org.apache.maven.plugins:maven-archetype-plugin:generate
mvn -DarchetypeGroupId=org.codehaus.mojo
-DarchetypeArtifactId=gwt-maven-plugin -DarchetypeVersion=2.3.0 -DgroupId={project packaging} -DartifactId={application name} -Dversion=1.0 -Dmodule={module name} org.apache.maven.plugins:maven-archetype-plugin:generate
(The value of archetypeVersion can be 2.3.0 or any higher stable version.)
Few coordinates are required by maven to create the gwt project. They are as follows:
groupId
artifactId
version
module
The first command doesn't take any of the above coordinates hence, we need to supply them at the time it executes. Notice that the archetype goal is mentioned right at the beginning of the command. It is mandatory to give the archetype goal.
The meanings of these coordinates can be found here.
One of the best ways to start with understanding maven is this.
The second command doesn't consider the module name hence, you will be prompted to give it at the time the command executes.
The third command is equivalent to running it in batch mode where you just have to confirm the inputs for groupId, artifactId, version, module as mentioned in command itself.
Once any of these commands gives a BUILD SUCCESS result, then navigate to the just-now-created project folder from command line and execute the following command:
mvn gwt:run
It should start the project in Development Mode so that you can Launch the Default Browser to run the project or Copy the URL to clipboard and navigate to it through any browser.
Good luck with the execution.

Intellij repackage dependencies in jarfile?

I am a big fan of jetbrains products, and am an intellij (community edition) user for all my java development. However there is one feature from eclipse that I REALLY miss. In eclipse, if I had a bunch of jarfile dependencies, I could repackage them in my runnable jar file so all dependencies were contained in one jar file.
I can not find anything that will get this done in intellij, so I am forced to export my projects to eclipse format from intellij, fix the project configuration in eclipse (since intellij doesnt do such a great job on the export) and then build my jarfiles from eclipse.
Have you taken a look at the build artifact component of IntelliJ? It allows you to define a JAR build artifact (executable or non-executable) that can include the dependencies either extracted within the target Jar or as a link within the Jar's Manifest file. See this blog entry for the details: http://blogs.jetbrains.com/idea/2010/08/quickly-create-jar-artifact/