Drools is throwing exception in Maven project - java

I created a drools project using the version 6.5.0.Final and is running fine. But when i created a maven project its throwing error
Caused by: java.lang.NoSuchMethodError: com.thoughtworks.xstream.XStream.fromXML(Ljava/net/URL;)Ljava/lang/Object;
at org.drools.compiler.kproject.models.KieModuleModelImpl$kModuleMarshaller.fromXML(KieModuleModelImpl.java:207)
at org.drools.compiler.kproject.models.KieModuleModelImpl.fromXML(KieModuleModelImpl.java:154)
at org.drools.compiler.kie.builder.impl.ClasspathKieProject.fetchKModule(ClasspathKieProject.java:179)
at org.drools.compiler.kie.builder.impl.ClasspathKieProject.fetchKModule(ClasspathKieProject.java:141)
at org.drools.compiler.kie.builder.impl.ClasspathKieProject.discoverKieModules(ClasspathKieProject.java:112)
at org.drools.compiler.kie.builder.impl.ClasspathKieProject.init(ClasspathKieProject.java:84)
at org.drools.compiler.kie.builder.impl.KieContainerImpl.<init>(KieContainerImpl.java:139)
at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieClasspathContainer(KieServicesImpl.java:135)
at org.drools.compiler.kie.builder.impl.KieServicesImpl.getKieClasspathContainer(KieServicesImpl.java:101)
at org.drools.compiler.kie.builder.impl.KieServicesImpl.getKieClasspathContainer(KieServicesImpl.java:79)
at com.powerschool.cc.validationengine.engine.ValidationEngine.getKieSession(ValidationEngine.java:49)
at com.powerschool.cc.validationengine.engine.ValidationEngine.validationEngine(ValidationEngine.java:24)
Here is my dependencies in POM file
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-api</artifactId>
<version>${runtime.version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>${runtime.version}</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-compiler</artifactId>
<version>${runtime.version}</version>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>${cdi.version}</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.se</groupId>
<artifactId>weld-se-core</artifactId>
<version>${weld.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.10-java7</version> </dependency>
</dependencies>
This is the code
private KieSession getKieSession(){
KieServices services = null;
KieContainer container = null;
KieSession kieSession = null;
try{
services = KieServices.Factory.get();
container = services.getKieClasspathContainer();
kieSession = container.newKieSession("ksession-rules");
}catch(Exception e){
e.printStackTrace();
}
return kieSession;
}
getKieClasspathContainer is throwing the error.
Googled the error and found that adding Xstream dependency will solve the issue but its not. Uing Java 7 and tomcat 7. Do i need to add any other dependency to the POM?
Anybody is having any idea?

The version in the dependency in your POM for xstream is 1.4.10-java7.
Drools 6.5.0-Final comes with the jar file xstream-1.4.9.jar and that means that the Drools jars have been compiled against this version.
I cannot guarantee that this is the reason why you get this error but it is worth a try.

Related

Classes loaded in classloader are note the same when launching in Intellij and Maven command on JUnit test

I have a git module project using maven and wicket and imported in IntelliJ.
I have also in a module, one test trying to test to load all classes present in dependencies used by the project to check if there is no encoding error in file *.properties (and other tasks).
When i launch it directly from Intellij(green play button close to the test name), the test is working and all classes from all dependencies are loaded, but when i launch with
mvn clean install
in terminal or from maven toolbar only classes in current project are loaded.
i tried all classloader possibilities but each time same result, with maven command only class in target/classes of current project are loaded in Classloader
this is my test
#Test
void testCheckMistakesInProperties() throws Exception {
var iter = Reflections.class.getClassLoader().getResources( "" ).asIterator();
//var iter = ClassLoader.getPlatformClassLoader().getResources( "" ).asIterator();
//var iter2 = ClassLoader.getSystemClassLoader().getResources( "" ).asIterator();
//var iter3 = AllWicketPagesTest.class.getClassLoader().getResources( "" ).asIterator();
while(iter.hasNext()){
var url = iter.next();
Path resourcesPath;;
try{
resourcesPath = Path.of( url.toURI() );
}catch(FileSystemNotFoundException e){
continue;
}
try( var pathStream = java.nio.file.Files.walk( resourcesPath ) ){
pathStream.forEach( path -> {
var pathStr = path.toString();
LOGGER.info( "Properties file checked {}", pathStr ); });
}catch(Exception e){
continue;
}
}
}
i tried all method (classLoader Helper etc...) nothing working
here my pom.xml
<dependencies>
<dependency>
<groupId>es.lib</groupId>
<artifactId>webapp</artifactId>
</dependency>
<dependency>
<groupId>es.java</groupId>
<artifactId>entities</artifactId>
</dependency>
<dependency>
<groupId>es.java</groupId>
<artifactId>entities</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.lib</groupId>
<artifactId>stockmarket</artifactId>
</dependency>
<dependency>
<groupId>com.java.intranet</groupId>
<artifactId>intranet-web</artifactId>
</dependency>
<dependency>
<groupId>org.wicketstuff</groupId>
<artifactId>wicketstuff-html5</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.webjars.npm</groupId>
<artifactId>bootstrap-tourist</artifactId>
</dependency>
<dependency>
<groupId>com.java</groupId>
<artifactId>base-entities</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.java</groupId>
<artifactId>web</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework</groupId>
<artifactId>jersey-test-framework-core</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-inmemory</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.icegreen</groupId>
<artifactId>greenmail-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency><!-- To provide the annotation processor in the IDE's classpath -->
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>Clean test database before the tests</id>
<phase>process-test-resources</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
It is a complicated project with a lot of parent pom, but i think only in this project we can fix the issue i want to be able to see in classloader classes from es.java lib or com.java
I think also with intellij it uses the project structure link to load dependencies classes(present as a submodule in editor)
even if i use a class from lib and retrieve classloader it will load only the current project (where my test is launched) to load only target/classes classes and not form jar or external lib/dependencies

Unable to Launch any Browser Drivers using Selenium, testng [duplicate]

I am trying to use Selenium api with Gradle. This is my build.gradle dependency section:
dependencies {
compile 'com.google.api-client:google-api-client:1.23.0'
compile 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
compile 'com.google.apis:google-api-services-sheets:v4-rev506-1.23.0'
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '2.9.0'
compile group: 'org.seleniumhq.selenium', name: 'selenium-chrome-driver', version: '2.9.0' }
My selenium - Java code:
System.setProperty("webdriver.chrome.driver", "C:\\Program Files(x86)\\Google\\Chrome\\Application\\chrome.exe");
WebDriver driver = new ChromeDriver();
Code works fine, and I am able to get Chrome browser opened.
However, in build.gradle, I am using 2.9.0 version of selenium and chromedriver. If I try to use any version after 2.9.0, it gives me below error in WebDriver driver = new ChromeDriver(); method:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
at Quickstart.main(Quickstart.java:130)
I tried looking for gradle+Maven+selenium supported version. Was not able to find any good info. Any idea?
Try to update your Guava to
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.1-jre</version>
</dependency>
It will solve your issue.
This error message...
Exception in thread "main" java.lang.NoSuchMethodError:
com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
...implies that the Java Client was unable to find ChromeDriver().
Issue & Solution
As per the Selenium - Java code you have shared, the System.setProperty() line is used to set the ChromeDriver binary path not the chrome binary path. For that you have to download the ChromeDriver binary from the ChromeDriver - WebDriver for Chrome and place it in your system and mention the absolute path of the ChromeDriver through System.setProperty() line. Hence you have to change :
System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
WebDriver driver = new ChromeDriver();
To :
System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
I have the exact same problem (I am using Maven though).
I noticed that the problem is that using one of com.google.api-client, or com.google.oauth-client, or com.google.apis:google-api-services-sheets alongside org.seleniumhq.selenium causes the error.
The problem is that both dependencies depend on a different com.google.guava:guava artifact.
In order to solve the error, you should explicitly depend on a single com.google.guava:guava artifact.
So go ahead and add the following in your build.gradle:
compile 'com.google.guava:guava:27.0.1-jre'
Just wanted to post here in case anyone else comes to this from Google like I did. For whatever reason, I needed to run with sudo. I was having issues using the npm selenium-standalone package and running:
/node_modules/selenium-standalone/bin/selenium-standalone start
And it would show that error. What fixed it was running with sudo
sudo /node_modules/selenium-standalone/bin/selenium-standalone start
I don't think I needed to do this before but suddenly it's the only way it works now.
I had the same problem and ran a dependency check and found that there were conflicts. The solution that worked for me was to exclude the conflicting dependencies.
Your project will probably have different dependencies than mine. So, listing the specific conflicts in my project may not be helpful.
copy and paste the following dependencies in the pom.xml and then do a maven build:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.1.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/json-path -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-path</artifactId>
<version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/json-schema-validator -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-schema-validator</artifactId>
<version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/xml-path -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>xml-path</artifactId>
<version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hamcrest/java-hamcrest -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>java-hamcrest</artifactId>
<version>2.0.0.0</version>
<scope>test</scope>
</dependency>
<!-- cucumber dependency begins -->
<!-- https://mvnrepository.com/artifact/net.masterthought/cucumber-reporting -->
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>4.7.0</version>
</dependency>
<!-- starts here -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>1.2.5</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-html -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-html</artifactId>
<version>0.2.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/gherkin -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>gherkin</artifactId>
<version>2.12.2</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>5.4.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.theoryinpractise/cucumber-testng-factory -->
<dependency>
<groupId>com.theoryinpractise</groupId>
<artifactId>cucumber-testng-factory</artifactId>
<version>1.0.1</version>
</dependency>
<!-- https://stackoverflow.com/questions/49021707/java-lang-nosuchmethoderror-com-google-common-base-preconditions-checkstatezlj?rq=1 -->
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.1-jre</version>
</dependency>
</dependencies>
Just adding the below was not enough
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.1-jre</version>
</dependency>
It was not working first. Then I moved this dependency up higher in pom.xml
than junit dependency and it worked. So, make sure that in pom file ,it is higher than junit or testng or whatever runner you are using
A comment in this post helped
Adding guava dependency and chromedriver version dependency worked for me -
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>25.0-jre</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.141.59</version>
<scope>test</scope>
</dependency>
Problem might be also in inclusion of the google-collections:
// https://mvnrepository.com/artifact/com.google.collections/google-collections
implementation 'com.google.collections:google-collections:1.0'
I had this included in one library that I linnked in and it drived me nuts finding the reason.
Including parameter -verbose:class into JVM helped to pinpoint the culprit.

Cucumber "You are using deprecated Main class. Please use io.cucumber.core.cli.Main" [duplicate]

i have updated my cucumber version after that it is giving following exception:
WARNING: You are using deprecated Main class. Please use
io.cucumber.core.api.cli.Main
Exception in thread "main" cucumber.runtime.CucumberException: Failed to
instantiate public
cucumber.runtime.java.JavaBackend(cucumber.runtime.io.ResourceLoader,io.cucum
ber.stepexpression.TypeRegistry)
My runner Class:
package hgtest.runner;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
#CucumberOptions(plugin = "json:target/cucumber-report.json",
features="classpath:features",
glue="hgtest.stepdefinitions"
)
public abstract class CustomCucumberAbstractTestng extends AbstractTestNGCucumberTests {
public CustomCucumberAbstractTestng() {
}
#Test(
groups = {"cucumber"},
description = "Runs Cucumber Feature",
dataProvider = "features"
)
#Override
#DataProvider(parallel = true)
public Object[][] scenarios() {
return super.scenarios();
}
}
Pom.xml is following:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>4.5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java8 -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>4.5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>4.5.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/gherkin -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin</artifactId>
<version>4.1.3</version>
</dependency>
I have updated the cucumber version from info.cuke to io.cucumber. After that it is saying Exception in thread "main" cucumber.runtime.CucumberException. There is no io.cucumber.core.api.cli.Main. I am using intellij Idea
I managed to force IntelliJ-cucumber plugin template to use the suggested io.cucumber.core.api.cli.Main, and it works.
As stated by #mpkorstanje:
The correct class to use is io.cucumber.core.api.Main
I had the same problem.
I put the dependencies below in pom.xml and implements the En interface in the class of steps the problem was solved.
<!-- cucumber -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>4.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-spring</artifactId>
<version>4.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.2.0</version>
<scope>test</scope>
</dependency>
In the official SmartBear forum, the creator and lead developer of Cucumber Open says:
"You can safely ignore this warning. All it means is that cucumber-eclipse has not yet been updated to use Cucumber's new package structure. We have an open issue about this. If you feel strongly about it you can help us by submitting a pull request to cucumber-eclipse."
https://community.smartbear.com/t5/Cucumber-Open/deprecated-Main-class-error-while-using-Cucumber-6-1-1/td-p/203642

Exception thrown while running unit tests for maven plugin - ComponentLookupException :: NoSuchElementException :: RepositorySystem

I'm trying to run unit tests to a Maven Plugin's Mojo using the artifact maven-plugin-testing-harness:3.3.0, with the following dependencies. But when I try to 'lookupEmptyMojo', the exception below is thrown. Any quick way to solve this configuration issue?
...
<properties>
<maven.api.version>3.6.2</maven.api.version>
<dependencies>
<!-- Maven plugin deps -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven.api.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.api.version}</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Tests -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>3.3.0</version>
<scope>test</scope>
</dependency>
</dependencies>
...
Exception:
org.codehaus.plexus.component.repository.exception.ComponentLookupException: java.util.NoSuchElementException
role: org.apache.maven.repository.RepositorySystem
roleHint:
at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:267)
...
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: java.util.NoSuchElementException
at org.eclipse.sisu.inject.LocatedBeans$Itr.next(LocatedBeans.java:141)
... 28 more
Coming back to report how to had fixed this issue.
I had to add two others dependencies: maven-compat and maven-resolver-api.
Test-harness uses Maven2 classes, so if we are using Maven3 we need to add the lib maven-compat with the same version of maven api that we are using; this lib implements back compatibility with the old api.
RepositorySystem is an interface present in the maven-resolver-api lib, which works with artifact repositories, that can be remote, local, or even build reactor or IDE workspace.
The dependencies were added to the pom like the following:
<dependency>
<groupId>org.apache.maven.resolver</groupId>
<artifactId>maven-resolver-api</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${maven.api.version}</version>
<scope>test</scope>
</dependency>

Selenium ChromeDriver throws NoSuchMethodException [duplicate]

I am trying to use Selenium api with Gradle. This is my build.gradle dependency section:
dependencies {
compile 'com.google.api-client:google-api-client:1.23.0'
compile 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
compile 'com.google.apis:google-api-services-sheets:v4-rev506-1.23.0'
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '2.9.0'
compile group: 'org.seleniumhq.selenium', name: 'selenium-chrome-driver', version: '2.9.0' }
My selenium - Java code:
System.setProperty("webdriver.chrome.driver", "C:\\Program Files(x86)\\Google\\Chrome\\Application\\chrome.exe");
WebDriver driver = new ChromeDriver();
Code works fine, and I am able to get Chrome browser opened.
However, in build.gradle, I am using 2.9.0 version of selenium and chromedriver. If I try to use any version after 2.9.0, it gives me below error in WebDriver driver = new ChromeDriver(); method:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
at Quickstart.main(Quickstart.java:130)
I tried looking for gradle+Maven+selenium supported version. Was not able to find any good info. Any idea?
Try to update your Guava to
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.1-jre</version>
</dependency>
It will solve your issue.
This error message...
Exception in thread "main" java.lang.NoSuchMethodError:
com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
...implies that the Java Client was unable to find ChromeDriver().
Issue & Solution
As per the Selenium - Java code you have shared, the System.setProperty() line is used to set the ChromeDriver binary path not the chrome binary path. For that you have to download the ChromeDriver binary from the ChromeDriver - WebDriver for Chrome and place it in your system and mention the absolute path of the ChromeDriver through System.setProperty() line. Hence you have to change :
System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
WebDriver driver = new ChromeDriver();
To :
System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
I have the exact same problem (I am using Maven though).
I noticed that the problem is that using one of com.google.api-client, or com.google.oauth-client, or com.google.apis:google-api-services-sheets alongside org.seleniumhq.selenium causes the error.
The problem is that both dependencies depend on a different com.google.guava:guava artifact.
In order to solve the error, you should explicitly depend on a single com.google.guava:guava artifact.
So go ahead and add the following in your build.gradle:
compile 'com.google.guava:guava:27.0.1-jre'
Just wanted to post here in case anyone else comes to this from Google like I did. For whatever reason, I needed to run with sudo. I was having issues using the npm selenium-standalone package and running:
/node_modules/selenium-standalone/bin/selenium-standalone start
And it would show that error. What fixed it was running with sudo
sudo /node_modules/selenium-standalone/bin/selenium-standalone start
I don't think I needed to do this before but suddenly it's the only way it works now.
I had the same problem and ran a dependency check and found that there were conflicts. The solution that worked for me was to exclude the conflicting dependencies.
Your project will probably have different dependencies than mine. So, listing the specific conflicts in my project may not be helpful.
copy and paste the following dependencies in the pom.xml and then do a maven build:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.1.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/json-path -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-path</artifactId>
<version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/json-schema-validator -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-schema-validator</artifactId>
<version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/xml-path -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>xml-path</artifactId>
<version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hamcrest/java-hamcrest -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>java-hamcrest</artifactId>
<version>2.0.0.0</version>
<scope>test</scope>
</dependency>
<!-- cucumber dependency begins -->
<!-- https://mvnrepository.com/artifact/net.masterthought/cucumber-reporting -->
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>4.7.0</version>
</dependency>
<!-- starts here -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm</artifactId>
<version>1.2.5</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-html -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-html</artifactId>
<version>0.2.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/gherkin -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>gherkin</artifactId>
<version>2.12.2</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>5.4.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.theoryinpractise/cucumber-testng-factory -->
<dependency>
<groupId>com.theoryinpractise</groupId>
<artifactId>cucumber-testng-factory</artifactId>
<version>1.0.1</version>
</dependency>
<!-- https://stackoverflow.com/questions/49021707/java-lang-nosuchmethoderror-com-google-common-base-preconditions-checkstatezlj?rq=1 -->
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.1-jre</version>
</dependency>
</dependencies>
Just adding the below was not enough
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>27.1-jre</version>
</dependency>
It was not working first. Then I moved this dependency up higher in pom.xml
than junit dependency and it worked. So, make sure that in pom file ,it is higher than junit or testng or whatever runner you are using
A comment in this post helped
Adding guava dependency and chromedriver version dependency worked for me -
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>25.0-jre</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.141.59</version>
<scope>test</scope>
</dependency>
Problem might be also in inclusion of the google-collections:
// https://mvnrepository.com/artifact/com.google.collections/google-collections
implementation 'com.google.collections:google-collections:1.0'
I had this included in one library that I linnked in and it drived me nuts finding the reason.
Including parameter -verbose:class into JVM helped to pinpoint the culprit.

Categories

Resources