not able to run "karate-demo" runners in VSCode because of karate-core classes cannot be resolved

Viewed 690

I've downloaded zip file (instead of repo cloning) from Karate´s gitlab home page (0.9.6 version) and also configured VS Code with java recommended stuff, but some imports are failing ...

This one from DemoLogModifier.java when trying

import com.intuit.karate.http.HttpLogModifier;

DemoLogModifier.java

With the error

The import com.intuit.karate.http.HttpLogModifier cannot be resolvedJava(268435846)

When using Intellij these errors are not there

I have 19 extensions installed

  • Cloudfoundry Manifest YML Support
  • Concourse CI Pipeline Editor
  • Cucumber (Gherkin) Full Support
  • Debugger for Java
  • ESLint
  • Java Extension Pack
  • Java Test Runner
  • Karate Runner
  • Language Support for Java(TM) by Red Hat
  • Maven for Java
  • Project Manager for Java
  • Python
  • SonarLint
  • Spring Boot Dashboard
  • Spring Boot Extension Pack
  • Spring Boot Tools
  • Spring Initializr Java Support
  • Visual Studio IntelliCode
  • XML

This is my settings json

{
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "java.configuration.checkProjectSettingsExclusions": false,
    "terminal.integrated.shell.osx": "/bin/zsh",
    "java.home": "/Library/Java/JavaVirtualMachines/jdk-11.0.9.jdk/Contents/Home",
    "java.configuration.runtimes": [
        {
          "name": "JavaSE-11",
          "path": "/Library/Java/JavaVirtualMachines/jdk-11.0.9.jdk/Contents/Home",
          "sources" : "/Library/Java/JavaVirtualMachines/jdk-11.0.9.jdk/Contents/Home/lib/src.zip",
          "javadoc" : "https://docs.oracle.com/en/java/javase/11/docs/api",
          "default":  true
         }
      ],
      "maven.executable.preferMavenWrapper": false,
      "maven.pomfile.autoUpdateEffectivePOM": true,
      "maven.terminal.useJavaHome": true,
      "java.maven.downloadSources": true
}

And this is my .zshrc

##JAVA
export JAVA_HOME="$(/usr/libexec/java_home)"
export PATH=$PATH:$JAVA_HOME/bin
export M2_HOME=/Users/agilcoto/Work/apache-maven-3.6.3
export MAVEN_HOME=$M2_HOME
export M2=$M2_HOME/bin
export MAVEN_OPTS="-Xms256m -Xmx512m"
export PATH=$PATH:$M2

Any clue? what's missing?

2 Answers

The ZIP release is intended for those not familiar with Java. I suggest you stick with Maven if you intend to a) use Java interop or b) use custom hooks or implement a log modifier etc

You can add custom Java compiled code to the classpath in the "standalone" option if you know what you are doing, here are some tips: https://stackoverflow.com/a/58398958/143475

Finally I was able to get to the root cause ...

VSCode, with my current configuration, it is using build.gradle file by default So, I have to make several updates to it

karate-demo/build.gradle

ext {
    springBootVersion = '1.5.3.RELEASE'
    springVersion = '4.3.8.RELEASE'
    gradleVersionProperty = '4.1'
    karateVersion = '0.9.6'
    masterThoughtVersion = '3.8.0'
    activeMqVersion = '5.15.2'
}

The update above is the karateVersion value, from 0.9.2 to 0.9.6

compile 'commons-io:commons-io:2.5'
compile 'commons-codec:commons-codec:1.15'
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'
runtime 'com.h2database:h2:1.4.196'

The update above are the commons-codec and javax modules, that weren't configured

Also I needed to add the commons-codec module to karate-demo/pom.xml file

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.4.196</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.15</version>
    </dependency>     
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.5</version>
    </dependency>

Finally there are still issues with standard sonarlint best practices at two files

/Users/agilcoto/Work/scratches/karate/karate-netty/src/main/java/com/intuit/karate/Main.java

The sonarlint extension is throwing the error Refactor this method to reduce its Cognitive Complexity from XX to the 15 allowed.sonarlint(java:S3776) for two methods:

  1. main: 17
  2. call: 18

/Users/agilcoto/Work/scratches/karate/karate-netty/src/test/java/com/intuit/karate/ProxyServerSslMain.java

The sonarlint extension is throwing the error Add at least one assertion to this test case.sonarlint(java:S2699) for the method testProxy

Final settings.json VSCode conf file must include, if sonarlint is enabled, this property

  "sonarlint.rules": {
    "java:S3776": {
      "level": "off"
    },
    "java:S2699": {
      "level": "off"
    }   }
Related