Trigger Gradle Task after import Eclipse Project - eclipse

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
}

Related

Import source code: Could not install Gradle distribution

Gradle
michael#michael:~$ gradle -v
------------------------------------------------------------
Gradle 6.3
------------------------------------------------------------
Java
michael#michael:~$ java -version
java version "14.0.1" 2020-04-14
Spring Tool Suite 4 (an Eclipse derivative)
Version: 4.6.0.RELEASE
Buildship
Eclipse Plug-ins for Gradle 3.1.4.v20200326-1743 org.eclipse.buildship.feature.group Eclipse Buildship
I've downloaded a code samples for a book.
Then:
File -> Import -> Existing Gradle Project.
When I import, I override workspace settings:
1. Gradle version = 6.3
2. Gradle user home = /opt/gradle/gradle-6.3/bin
3. Java home = /usr/lib/jvm/jdk-14.0.1/bin
The same as described above:
The problem:
Description Resource Path Location Type
Could not install Gradle distribution from 'https://services.gradle.org/distributions/gradle-6.3-bin.zip'.
Could not create parent directory for lock file /opt/gradle/gradle-6.3/bin/wrapper/dists/gradle-6.3-bin/8tpu6egwsccjzp10c1jckl0rx/gradle-6.3-bin.zip.lck beginning-spring-5 line 0 Gradle Error Marker
The same as a picture:
Well, STS seems to be trying to install Gradle.
Could you help me understand what is going on and help cope with this.
If I do everything wrongly, please help me just import the source code.

Gradle Build Configuration help - Eclipse Oxygen

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.

Add scalacheck dependency to gradle project

I am trying to use scalaCheck (https://github.com/rickynils/scalacheck) to a gradle project. However, adding it this way:
dependencies {
...
compile group: 'org.scalacheck', name: 'scalacheck_2.11', version: '1.12.5'
...
}
doesn't seem to be doing the trick. I also tried to add it in a maven project. In both cases, trying to do the following
import org.scalacheck.Prop.forAll
reports the error
object scalacheck is not a member of package org
I ran "gradle dependencies" before trying to import it, and it seemed to download everything just fine, finishing the command without throwing errors. Is there a way to add scalacheck to my project and if so, how?
Note: not sure if relevant, but I am using Eclipse Neon with all the scala plugins.
(So it seems the problem was with using the eclipse gradle integration.) You have to manually update the project by using the Gradle | Refresh Gradle Project from the project's context menu on each dependency change (though it might be useful to do that on each change to gradle configuration files).

How to pass parameters to gradle in eclipse Buildship plugin while importing project

I'm importing a gradle project requiring parameters into eclipse neon using the buildship gradle plugin. Here is a fragment of the build.gradle with parameters:
repositories {
maven {
url repoUrl
credentials {
username repoUsername
password repoPassword
}
}
}
I usually just add the parameters on the gradle command line:
gradlew eclipse build -PrepoUrl="http://localhost:9080/nexus/content/groups/internal/" -PrepoUsername="user1" -PrepoPassword="xxxxxxxxxx"
I can't find a possibility to pass the parameters while importing the project with the Buildship plugin. I'm using version 2.0.0 on neon release.
Setting the GRADLE_OPTS environment variable doesn't help as it doesn't seem to be used by the plugin.
Is there another way to set the variables from outside so the credentials aren't stored in the project files?
You should go Window->Preferences->Gradle and then pass your arguments into "Program Arguments" section

Gradle dependency sources not appearing in Eclipse for the War Plugin

I am working on a Java web project that uses Gradle (version 2.1) as the build dependency tool. I use Eclipse Luna as my IDE. My OS is Mac 10.9 (Mavericks).
This is my build.gradle file (very basic and stripped down for ease of illustration):
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
sourceCompatibility = 1.8
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
compile group: 'com.google.inject', name: 'guice', version: '3.0'
}
So just one dependency, Guice. I will generate my Eclipse classpath and project files using gradle cleanEclipse eclipse. Then I will import an existing project into my workspace. I like being able to view the source code of my dependencies in my Eclipse projects, so I will open a Guice class, such as com.google.inject.Injector, using CMD-SHIFT-T. And voila, the source code of that file will appear.
But I working on a web project, so I need to be able to build a WAR file instead of a JAR file. Therefore, I am going to apply the Gradle War Plugin by replacing apply plugin: 'java' with apply plugin: 'war'. Then I rerun gradle cleanEclipse eclipse and reopen my project.
Now, instead of seeing the source code when I open up Injector, I will see the bytecode viewer with the Attach Source button. Anyone have any ideas whether it's something I'm forgetting in my build.gradle file or if it could be a bug in Gradle/Eclipse?
Note that I am not using the Gradle Integration for Eclipse Plugin because I wish to pinpoint the root cause of this issue without adding an extra layer of complexity to it. I have also checked other SOF questions about Attach Source issue with Gradle and Eclispe, such as how to tell gradle to download all the source jars and Why is Eclipse not attaching 3rd party libs source files to a WTP-faceted Gradle project?, but to no avail.