In Eclipse: Could not find or load main class org.testng.remote.RemoteTestNG - eclipse

Configuration
I have version 2019-12 (4.14.0) of Eclipse (having recently upgraded from 2019-03) with the following plugins installed (amongst others):
TestNG 6.14.3.201902250526
TestNG M2E (Maven) Integration (Optional) 6.14.3.201902250526
TestNG P2 Features 6.14.3.r201802240500
Eclipse is running against jdk1.8.0_152.
In Eclipse, my Java Build Path includes testng-6.14.3. I've tried to match the Eclipse plugin version against the version using in the project.
Under Properties -> TestNG I have all the default settings. There is no setting here for "Use Project TestNG.jar".
What Works
When I run tests from the command line with Gradle they all pass with no issue.
There are no complile errors showing in Eclipse.
What Does Not Work
When I run a test from Eclipse (by right clicking on a class) the console shows:
Error: Could not find or load main class org.testng.remote.RemoteTestNG
It appears I need a copy of testng-remote.jar. Should this have been installed as part of the plug-in, or am I meant to have included that in my build.gradle as a dependency?
Why can't I run tests from Eclipse? Do I need to install something further to resolve this error?
What I have Tried
I have tried removing and re-installing the TestNG plugin.

It seems you hit the bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=558495 in Windows.
I reverted my version back to 2019-09 because of it.
The bug causes jars which should be on the classpath not to be on the classpath. This affects projects with long classpaths.

Can you try adding it in your build.gradle.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
classpath group: 'org.testng', name: 'testng', version: '6.8.+'
} }
Change the testng version as per your usage.

I don't remember such problem for gradle but it looks similar to the problem with testing on maven(with auto-build turned off). The soultion is to rebuild project (for maven it ia alt +f5) and because of such rebuilding - cache is updated.

You have detailed TestNG gradle tutorial
By default, Gradle will run all tests that it detects, which it does by inspecting the compiled test classes. When we specify useTestNG(), Gradle scans for all the methods annotated with #Test and execute them.
Example 1. Below is the basic configuration for the 'test' task
plugins {
id 'java'
}
group 'com.test'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.testng', name: 'testng', version: '6.14.3'
}
test {
useTestNG()
}
For Gradle use testCompile dependencies:
repositories {
jcenter()
}
dependencies {
testCompile 'org.testng:testng:6.10'
}
For specific version you have options,
Install from update site
Select Help / Install New Software...
Enter the update site URL in "Work with:" field:
Update site for release: http://dl.bintray.com/testng-team/testng-eclipse-release/.
Make sure the check box next to URL is checked and click Next.
Eclipse will then guide you through the process.
You can also install older versions of the plug-ins here. Note that the URL's on this page are update sites as well, not direct download links.
Build TestNG from source code
you can download the source and build the distribution yourself:
git clone git://github.com/cbeust/testng.git
cd testng
./build-with-gradle

Related

How to build an Xtext Eclipse plug-in with Gradle?

I have written a DSL with Xtext 2.12 and my Xtend 2.12 code generator produces Java 8 code from it. I am using Eclipse Oxygen.3a. I started by creating an Xtext project as an Eclipse plug-in and all works fine, but I would like to have everything built by Gradle now.
For that purpose, I have added the Gradle nature to my Xtext project and launched 'gradle init' to generate the build.gradle and settings.gradle files. I have discovered the existence of Xtext Gradle Plugins (Xtext Builder and Xtend Compiler), and used the documentation of these plugins to write the build.gradle script content, but I did not understand everything and, not surprisingly, my builder does not work. Could you help me please to set this builder up correctly?
plugins {
id 'org.xtext.builder' version '2.0.3'
id "org.xtext.xtend" version "2.0.3"
}
apply plugin: 'java'
apply plugin: 'org.xtext.xtend'
apply plugin: 'eclipse'
sourceSets {
main.java.srcDirs = ['src','xtend-gen']
main.xtendOutputDir = 'xtend-gen'
}
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile group: 'org.eclipse.xtend', name: 'org.eclipse.xtend.lib', version: '2.16.0'
compile group: 'org.eclipse.xtext', name: 'org.eclipse.xtext', version: '2.16.0'
compile group: 'org.eclipse.emf', name: 'org.eclipse.emf.codegen.ecore', version: '2.15.0'
compile group: 'org.eclipse.xtext', name: 'org.eclipse.xtext.xtext.generator', version: '2.16.0'
testCompile group: 'org.eclipse.xtext', name: 'org.eclipse.xtext.xbase.testing', version: '2.16.0'
}
xtext {
languages {
mapy {
setup = 'com.mchp.mapy.MapyStandaloneSetup'
generator.outlet.producesJava = true
}
}
sourceSets {
main {
srcDirs 'src','xtend-gen'
output {
dir(xtext.languages.mapy.generator.outlet, 'src-gen')
}
}
}
}
xtend {
}
Where should the sourceSets block be located (inside or outside the
xtext block)?
Is the xtext block content correct?
What should I write into the xtend block? Should it even be declared?
What is the Gradle task to be run to start the MWE2 launcher and
then the code generator?
Following is a snapshot of my Eclipse project organization.
Thanks in advance for your time!
It is also possible to build the Xtext plugins using Eclipse PDE. I created a dedicated Eclipse deployment to keep the size down (minimal then install the PDE, JDT and Xtext projects) which is published to an artifact repository. It's then just a matter of writing Gradle tasks (or a plugin) to pull down the Eclipse, extract it to the build directory, copy in the Xtext Eclipse projects (use the Xtext Gradle plugin to build the DSL before copying) and finally call the Ant PDE task(s) using the Java command and the AntRunner inside the Eclipse. The output should be a basic update site from which you can either install the plugins from locally or publish to the Artifact repository to share.
A good understanding of Eclipse PDE build process is required. I found most of what I needed in the Eclipse help (https://help.eclipse.org/2020-06/index.jsp) under section "Plug-in Development Environment Guide > Tasks > PDE Build"
I have encountered some issues during Xtext version upgrades with various dependency conflicts and Eclipse bugs. These can usually be resolved with the help of the Xtext dev team and then forcing certain dependencies in Gradle.
Unfortunately I can't share any of the build as it's a proprietary code, but I hope the explanation above is enough for anyone who needs to automate the process. It's certainly not a simple thing to set up though.

How to make Gradle add Lombok to its Project and external dependencies libraries?

I created a Java project in Eclipse Neon. I used Buildship 1.0.21 to import the project as a Gradle project and ran the wrapper and init commands to generate the build, settings and wrapper files.
The project has an empty source folder because I am trying to solve a similar problem on a more complicated project and taking the divide and conquer approach - just add Lombok dependency.
Here is my build.gradle as instructed on the lombok website:
apply plugin: 'java'
dependencies {
compileOnly "org.projectlombok:lombok:1.16.12"
}
and gradle-wrapper.properties if needed:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.2.1-bin.zip /* <--- tried other versions too */
and I ran the jar file to install it on my eclipse. If I add the jar manually via "Java Build Path" it works but I want Gradle to handle this for me. When I refresh the project nothing happens - there is no lombok jar under "Projects and External Dependencies" and code relying on lombok will give errors.
There is another project I have which does have it there and I don't know what I did differently but I know it's possible.
I managed to solve this after trial and error. The build.gradle file must add the jcenter repository:
repositories {
jcenter()
}
Why this is the case and why this is not mentioned anywhere I don't know. But for now this is what works.

How to setup JUnit testing in Gluon Project with Gradle

I am trying to setup JUnit testing in my Gluon JavaFX Application. I am using the Gluon Eclipse Plugin with Gradle and Java 8.
My build.gradle file looks like this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.0.0-b10'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
}
dependencies {
compile 'com.gluonhq:ignite-dagger:1.0.0'
compile 'org.elasticsearch:elasticsearch:1.6.0'
compile 'ch.qos.logback:logback-classic:1.1.5'
testCompile 'junit:junit:4.12'
}
mainClassName = 'com.me.MyApplication'
jfxmobile {
android {
manifest = 'src/android/AndroidManifest.xml'
}
ios {
infoPList = file('src/ios/Default-Info.plist')
}
}
Resolving the dependency is no problem, but when running the 'test' task, gradle throws an error like this:
When running gradle with java 8, you must set the path to the old jdk, either with property retrolambda.oldJdk or environment variable JAVA6_HOME/JAVA7_HOME
Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-2.2.1-all.zip'.
I already tried to add the retrolambda plugin to gradle according to the plugin's README on GitHub, but it doesn't work so far. Could someone tell me what to do to configure my Gluon project so that I am able to run my JUnit tests with Gradle?
Some important addidtions:
For the plugin version it says: Gluon Tools 1.0.0.201508201514
I think I fogot to mention that I want to use Dagger dependency injection with Gluon Ignite which might be the real problem in my case as it requires Java 8 and might conflict with javafxports or something else. However, I'm not able to make full sense of the various error messages I've seen.
My tests are empty, but they aren't even run, because it fails before.
Your problem seems like a retroLambda configuration issue. If you go through the configuration page for the plugin, it states that if you don't have an environment variable set for JAVA6_HOME or JAVA7_HOME than you need to explicitly define oldJdk for the plugin to work properly.

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.

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