Eclipse build path missing - eclipse

Hi I am working on a project and I have imported it via gitHub. I am importing it as a general project, it won't work otherwise. The problem I have is that there is no buildpath for the project. From java I can't run any of the files but I can run it fine in source tree with gradle.
I have read up on it and it says the way to fix it is:
Right-click > properties > build path
That or similar options but in my eclipse there is no BUILD PATH option.
I have tried looking at some fixes here and here. From the second link I have found that the following files are missing:
.classpath
.settings/*

If the project has a gradle wrapper in the root of the project then use it to invoke the tasks cleanEclipse eclipse to produce the eclipse artifacts.
Assuming you're on unix type system:
./gradlew cleanEclipse eclipse
If you're on windows, use gradlew.bat instead.
If the GitHub project didn't have a gradle wrapper, then you can use a system version of gradle instead.
This all assumes the project has following in it. If not add it to the main build script:
apply plugin: 'eclipse'

Related

When I create a gradle project in eclipse, there is this "lib" folder. I thought it shouldn't be here? What am I doing wrong? [duplicate]

When trying to create a gradle project in eclipse, the source folder, build.gradle and others are stored in a different folder called lib as a separate project.
How can I make all the folders be within the project folder like in a normal java project?
The problem is that the New Gradle Project dialog invokes the Gradle init task with the hard-coded argument --type java-library and that the project layout for Gradle versions higher than 6.6.1 has a lib folder besides the main project folder for a project of the type java-library (in contrast to in Gradle 6.6.1 or lower and in contrast to a project of the type application independent of the Gradle version).
In the future, in the New Gradle Project dialog, the type application should also be chooseable, to get a simple project structure like in the past. But this is not implemented yet:
Eclipse Buildship issue #1118: Add more project templates to New Gradle Project wizard
As a workaround do the following:
In the New Gradle Project dialog on the second or third page, check Override workspace settings and
choose as Specific Gradle version the version 6.6.1 and
for Java home a Java 11 JDK
In the build.gradle change id 'java-library' to id 'application'
In Project > Properties: Gradle choose a higher Gradle version
The last two steps are only required to use a Gradle version higher than 6.6.1.

Do dependencies need to be added through both the Eclipse GUI and the Gradle configuration files?

Two Gradle Git projects need to be created, within the same repository, using the Eclipse IDE. Project A depends upon a third-party library (a JAR, source code, Javadoc and natives) and project B depends upon project A.
Without Gradle, both projects would be created and Git would be enabled with Project Explorer > [Project Name] > Team > Share Project. Then, dependencies would be added via Project Explorer > [Project Name] > Build Path > Configure Build Path, followed by Projects > Add and Libraries > Add External JARs (which would also allow the specification of the locations of related source code, Javadoc and natives). This would enable automatic code completion of Project A from Project B as well as source code and Javadoc integration, within Eclipse.
With Gradle, should the settings.gradle or build.gradle files be manually edited, without adding dependencies through the Eclipse GUI, or must both be used simultaneously? Additionally,how does this effect which hidden files should be indexed by Git (.project, .classpath, .settings, .gradle)?
How is this setup through Eclipse and Gradle?
When you use a build-tool like Gradle (or maven), it is kind of assumed that the build-tool is in charge of configuring stuff like project dependencies and classpaths.
This kind of conflicts with the Eclipse UI which is kind of built to allow you to manage classpath / dependencies via its own ui.
But the Eclipse UI only controls what eclipse uses as the classpath when the Eclipse JDT compiler compiles your code... inside Eclipse.
So if you change things that way, then Gradle will not know about these dependencies and the build won't work.
Yep, this is definitely confusing :-)
The proper thing to do is manage your dependencies and project configuration entirely through gradle. So that means editing the build.gradle and settings.gradle.
The tools (BuildShip or STS Gradle Tools) provide a 'bridge' to try and configure Eclipse projects in conformance with your build.
E.g they may offer a 'Update Project' or 'Refresh Dependencies' command in project context menu.
Even if you don't use Gradle tooling, this kind of holds true. You then would use Gradle's 'ecplise' plugin and run a command like
gradle cleanEclipse eclipse
To generate the eclipse project config from the build config. Then import the project into Eclipse as configured by gradle. Also in this case, it would be a bad idea to use Eclipse UI to make changes to the buildpath since ultimately it has the same issue, changes you make to those generated files may make things compile inside Eclipse, but Gradle doesn't know you changed anything. And the next time you run gradle cleanEclipse eclipse your changes are also blown away.
As to your specific questions:
should the settings.gradle or build.gradle files be manually edited ...
Yes.
... without adding dependencies through the Eclipse GUI ...
Yes.
... or must both be used simultaneously?
No, only configure things in gradle. Then 'synch it up' to eclipse with some tool (BuildShip / STS Gradle / gradle cleanEclipse eclipse)
How does this effect which hidden files should be indexed by Git (.project, .classpath, .settings, .gradle)?
General rule of thumb. Only index the stuff that defines gradle's behaviour (there may be some exceptions, but in general try to minimize them only violate this rule if you have a good reason).
So specifically don't put in git these 'eclipse metadata'
.settings
.project
.classpath
Do put in git: the gradle wrapper and its properties file.
Gradle also has a .gradle folder. It belongs to gradle, not eclipse, buts is caches and things which are 'transient'. You don't want those in git either.

Gradle Eclipse Plugin only half-working

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.

Gradle IDE (Eclipse) Documentation

I am learning Gradle and have found my way around the normal use case. But now I have to step into integration with Eclipse (specifically STS) and need to learn more about how "Gradle projects" are imported into Eclipse (without having to generate the .project files using the inverse - Eclipse plugin for Gradle). By just attempting it I discovered that it did import my projects. However, projects written in Scala (some are pure Java, some Scala, some mixed) were not recognized and applied as Scala projects. In fact, Eclipse attempted to compile ".scala" files as if they were ".java" somehow and obviously failed miserably.
Tried Googling around to find more documentation on Eclipse integration but this appears to be significantly obscured by the "eclipse plugin" for Gradle in search results. Can someone, please, point me at documentation, if available, or provide at least some guidance with respect to my problem above...
Thanks!
I'm not sure what you mean by:
without having to generate the .project files using the inverse - Eclipse plugin for Gradle
Does this mean that you don't want to apply the Eclipse plugin in your Gradle project? Can I ask why? My experience of it has been very positive.
Here's what I've done in such cases:
apply the Eclipse plugin in my Gradle project (apply plugin: 'eclipse')
run the 'eclipse' Gradle task (gradle eclipse)
in Eclipse, do File>Import...>Existing projects into workspace and navigate to the Gradle project directory (or the root directory of a multi-project structure); (don't check Copy projects into workspace)
If the Gradle project also applies the Java plugin, you'll get a .project file that declares a javanature and refers to the javabuilder, and a .classpath file will also be generated. If not, you'll just get a vanilla .project file. The Gradle documentation makes it sound very much as if a similar thing applies in the case of the Scala plugin: http://www.gradle.org/docs/current/userguide/scala_plugin.html#N12EC0. Does this not work for you?

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.