Gradle Build Configuration help - Eclipse Oxygen - eclipse

I'm using eclipse oxygen and i was trying to run Gradle Buid on build.gradle file. I have installed Buildship Gradle Integration 2.0 and also configured the dependencies. The issue is when i right click on build.gradle and try to run as, i don't have the option Grade Build.

Instead of right-clicking the build.gradle file use the Gradle Tasks view to execute a Gradle task:
Window > Show View > Others...: Gradle > Gradle Tasks
Double-click a task
See also my short video on how to execute a Gradle task.

Related

"Gradle --> Refresh Gradle Project" in Eclipse removes classpath entries

I have a Gradle (6.6.1) project on Eclipse with Gradle Buildship 3.0.
When I do a project refresh (Gradle --> Refresh Gradle Project), my classpath entries are wiped out (Project Properties --> Java Build Path --> Libraries).
I can get them back by running the gradle task "eclipse". But, why do they disappear on refreshing the project? Is there a way to customize what happens when I do the Gradle Project Refresh ? If I can just run the "eclipse" gradle task as part of that project refresh.

How do I set up my JavaFX project as a Gradle build?

I've created a new JavaFX project via the e(fx)clipse plugin, then staged and committed to Git. Following that I tried to run it and got a 'class not found' error - needed to add JavaFX to the --module-path in VM arguments. But it still won't run:
Error: Could not find or load main class Files\Java\AdoptOpenJDK\javafx-sdk-13.0.2\lib
Caused by: java.lang.ClassNotFoundException: Files\Java\AdoptOpenJDK\javafx-sdk-13.0.2\lib
Then I noticed that I have no build files in the project tree - no pom.xml or build.gradle, etc.
I decided to build with Gradle (previously only used Maven). After a lot of hunting on the net I did the following:
Project context menu -> Configure -> Add Gradle nature (this didn't visibly do anything, but the option is no longer available).
In the Gradle Tasks view, run init. (This ran fine until it got to Execute setupProjectLayout for :init. This got stuck and I let it sit for about 20 mins, but there was no activity (checked task manager to confirm)).
There must be something fundamental that I'm missing here, surely it shouldn't be this difficult. How can I get this project to build in Gradle?
The Gradle init task is an interactive task to generate a new Gradle project. If you run it from the IDE but have no way to provide answers to the prompts from Gradle, it will indeed wait forever on an input.
You do not need a CLI for input.
After you run the gradle task in the "Gradle Tasks" view you switch to the "Console" view and you are presented with the questions by gradle init. You answer those questions and finish the task.
Working Directory: /path/to/your/project/thenewgradleproject
Gradle user home: /home/user/.gradle
Gradle Distribution: Gradle wrapper from target build
Gradle Version: 6.8
Java Home: /usr/lib/jvm/java-11-openjdk-amd64
JVM Arguments: None
Program Arguments: None
Build Scans Enabled: false
Offline Mode Enabled: false
Gradle Tasks: init
> Task :wrapper UP-TO-DATE
Select type of project to generate:
1: basic
2: application
3: library
4: Gradle plugin
Enter selection (default: basic) [1..4]
> Task :init
Select build script DSL:
1: Groovy
2: Kotlin
Enter selection (default: Groovy) [1..2]
Project name (default: thenewgradleproject):
> Task :init
Get more help with your project: Learn more about Gradle by exploring our samples at https://docs.gradle.org/6.8/samples
BUILD SUCCESSFUL in 53s
2 actionable tasks: 1 executed, 1 up-to-date

Trigger Gradle Task after import Eclipse Project

We ported our custom Gradle setup (GWT, builder configuration etc.) for Eclipse from the STS Gradle Plugin to the Buildship Plugin.
We use special self-developed tasks which are performed automatically after an import of a Gradle project through the STS plugin via the eclipse-task and afterEclipseImport-task. Does the new Buildship plugin allow to trigger tasks after the import in Eclipse in a similar manner?
Has anyone of you successfully triggered a Gradle task after project import with the Gradle Buildship plugin?
Better late than never: It has been introduced in Buildship 3.1 and requires Gradle 5.4 or above:
https://www.eclipse.org/community/eclipse_newsletter/2019/june/buildship.php
You can register tasks to be executed every time Eclipse is synchronizing the workspace with the working copy:
eclipse {
synchronizationTasks myCustomSyncTask
}
And tasks to be executed every time Eclipse is performing a build:
eclipse {
autoBuildTasks myCustomBuildTask
}

Eclipse won't resolve new Gradle dependencies

I'm new to Gradle and have the Gradle Eclipse plugin (running Spring Tool Suite). Whenever I add a new dependency in the Gradle build file, like this for example:
dependencies {
...
compile 'javax.validation:validation-api:1.1.0.Final'
compile 'org.hibernate:hibernate-validator:5.0.1.Final'
...
}
Eclipse can't resolve the imports in the classes that need these. What am I missing here?
Is there some "update project" command I need to run?
I see... I needed to right-click the build.gradle file -> Gradle -> Refresh Dependencies.

Update my gradle dependencies in eclipse

I have a simple gradle project in my eclipse. I update the build.gradle to include a few apache http jars...
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
compile 'org.apache.httpcomponents:httpclient:4.2.3'
compile "org.apache.httpcomponents:httpmime:4.2.3"
testCompile group: 'junit', name: 'junit', version: '4.+'
}
However in my code, where I reference some Apache HTTP stuff I get:
The import org.apache.http cannot be resolved
Any tips on what I need to do to make Eclipse see the new dependencies in my build.gradle?
I tried doing a clean but that does not work. My gradle plugin is:
Gradle IDE 3.3.0.201307040643-RELEASE org.springsource.ide.eclipse.gradle.feature.feature.group GoPivotal, Inc.
You have to select "Refresh Dependencies" in the "Gradle" context menu that appears when you right-click the project in the Package Explorer.
Follow those steps to update Gradle project in Eclipse:
First, please check you have include eclipse gradle plugin. apply plugin : 'eclipse'
Then go to your project directory in Terminal. Type gradle clean and then gradle eclipse.
Then go to project in eclipse and refresh the project (Go to Project Explorer, select root of the project and hit F5 to refresh, or right click and select refresh in context menu).
Looking at the Eclipse plugin docs I found some useful tasks that rebuilt my classpath and updated the required dependencies.
First try gradle cleanEclipse to clean the Eclipse configuration completely. If this doesn;t work you may try more specific tasks:
gradle cleanEclipseProject to remove the .project file
gradle cleanEclipseClasspath to empty the project's classpath
Finally gradle eclipse to rebuild the Eclipse configuration
You have to make sure that "Dependency Management" is enabled. To do so, right click on the project name, go to the "Gradle" sub-menu and click on "Enable Dependency Management". Once you do that, Gradle should load all the dependencies for you.
I tried all above options but was still getting error, in my case issue was I have not setup gradle installation directory in eclipse, following worked:
eclipse -> Window -> Preferences -> Gradle -> "Select Local
Installation Directory"
Click on Browse button and provide path.
Even though question is answered, thought to share in case somebody else is facing similar issue.
Cheers !
In my case, I solved weird issues in Spring Tools Suite (essentially Eclipse) after I tried to upgrade Spring Boot and the changes didn't seem to be taking effect.
Right click on your project -> Gradle -> Refresh Gradle Project