2

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?

Ton
  • 101
  • 1
  • 5

2 Answers2

0

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

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Thanks Peter. I just zipped the repo and unzipped locally. All other folders are ok, just karate-demo is failing – Ton Nov 10 '20 at 13:47
  • I mean, that error is prompted by VSCode Interface without doing anything – Ton Nov 10 '20 at 14:09
  • @Ton I have no other ideas - hopefully someone else or a VS code expert can help here – Peter Thomas Nov 10 '20 at 14:11
  • 1
    @Ton can you try the demo project here and confirm if it works in VSCode. https://github.com/kirksl/karate-maven-gradle If it does I would do some process of elimination between your project and this one to hone in on the issue. Generally if you can make Maven, Gradle and Karate.jar work from the command line it should work from VSCode as it is effectively just constructing a command line call for convenience. Please let us know what you find out. – Captain Kirk Nov 10 '20 at 16:21
  • Thank you @CaptainKirk I have downloaded your repo zip, unzipped and copied 'karate-demo' folder from karate directory. This is now the `ls`command output "bin, build, build.gradle, gradle, gradle.properties, gradlew, gradlew.bat, karate-demo, mvnw, mvnw.cmd, pom.xml, README.md, src" and no error shown in VSCode. "Project And External Dependencies" at "JAVA PROJECTS" section shows: "/Users/agilcoto/.gradle/caches/modules-2/files-2.1/com.intuit.karate/karate-apache/0.9.6/9c030562ac554d5360bb5ce5e55f53fb6e821dd9/karate-apache-0.9.6.jar" ... [more on next comment] ... – Ton Nov 11 '20 at 08:45
  • The rest of karate* stuff at JAVA PROJECTS: /Users/agilcoto/.gradle/caches/modules-2/files-2.1/com.intuit.karate/karate-core/0.9.6/9af3ab1a8ce3f968da760b7faa983ea97bf49db3/karate-core-0.9.6.jar /Users/agilcoto/.gradle/caches/modules-2/files-2.1/com.intuit.karate/karate-gatling/0.9.6/4a2116f03c2533a6d071ce01bf0a95ffa7bd7d6e/karate-gatling-0.9.6.jar /Users/agilcoto/.gradle/caches/modules-2/files-2.1/com.intuit.karate/karate-junit5/0.9.6/2217d460f8dfc4f5e8499bceaefe8fdedd24832/karate-junit5-0.9.6.jar – Ton Nov 11 '20 at 08:47
  • And last one ... /Users/agilcoto/.gradle/caches/modules-2/files-2.1/com.intuit.karate/karate-mock-servlet/0.9.6/e85d957f82829820f7aa0ae11e74a30048786754/karate-mock-servlet-0.9.6.jar – Ton Nov 11 '20 at 08:47
  • Is it enough with just copying 'karate-demo' folder into project "root" folder? I am getting this warning in the DemoLogModifier.java file ... `DemoLogModifier.java is not on the classpath of project karate-maven-gradle-master, it will not be compiled to a .class fileJava(32)` – Ton Nov 11 '20 at 08:56
  • I have found that same "Project And External Dependencies" at JAVA PROJECTS section for `karate` project is returning version 0.9.2 instead of version 0.9.6 for karate* jars ... /Users/agilcoto/.gradle/caches/modules-2/files-2.1/com.intuit.karate/karate-core/0.9.2/aebafaddcc80d7e72a8f235109cf4730ac8d92d9/karate-core-0.9.2.jar – Ton Nov 11 '20 at 11:51
0

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"
    }   }
Ton
  • 101
  • 1
  • 5